Skip to content

Commit 65fe3c8

Browse files
committed
deprecate scalaModuleSettingsJVM, use scalaModuleOsgiSettings instead
1 parent 841b394 commit 65fe3c8

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This is an sbt 1.x plugin for building Scala modules.
44

55
## What modules use it?
66

7+
* [travis-test](https://github.com/lrytz/travis-test) (example project for testing this plugin and tag-driven releases)
78
* [scala-async](https://github.com/scala/scala-async)
89
* [scala-collection-compat](https://github.com/scala/scala-collection-compat)
910
* [scala-collection-contrib](https://github.com/scala/scala-collection-contrib)
@@ -18,7 +19,7 @@ This is an sbt 1.x plugin for building Scala modules.
1819
## Why this plugin?
1920

2021
Having a shared plugin reduces duplication between the above
21-
repositories. Reducing duplication makes maintenance easier and
22+
repositories. Reducing duplication makes maintenance easier and
2223
helps ensure consistency.
2324

2425
A major feature of the plugin is automated tag-based publishing using
@@ -28,14 +29,14 @@ The plugin also brings in
2829
- sbt-travisci to set the `scalaVersion` and `crossScalaVersions`
2930
- sbt-dynver to set the `version` based on the git history
3031
- sbt-header
31-
- sbt-osgi
32+
- sbt-osgi (only enabled when using `scalaModuleOsgiSettings`)
3233

3334
## Usage
3435

3536
Add the plugin to the `project/plugins.sbt` file:
3637

3738
```
38-
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.1.0")
39+
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.2.0")
3940
```
4041

4142
Then, in your `build.sbt` add:
@@ -45,14 +46,14 @@ Then, in your `build.sbt` add:
4546
// main project (see e.g. scala-parallel-collections)
4647
ScalaModulePlugin.scalaModuleSettings
4748
48-
// For JVM projects
49-
ScalaModulePlugin.scalaModuleSettingsJVM
49+
// If making an OSGi bundle
50+
ScalaModulePlugin.scalaModuleOsgiSettings
5051
5152
name := "<module name>"
5253
repoName := "<GitHub repo name>" // the repo under github.com/scala/, only required if different from name
5354
organization := "<org>" // only required if different from "org.scala-lang.modules"
5455
55-
mimaPreviousVersion := Some("1.0.0") // enables MiMa (`None` by default, which disables it)
56+
scalaModuleMimaPreviousVersion := Some("1.0.0") // enables MiMa (`None` by default, which disables it)
5657
5758
OsgiKeys.exportPackage := Seq(s"<exported package>;version=${version.value}")
5859
@@ -61,13 +62,13 @@ OsgiKeys.exportPackage := Seq(s"<exported package>;version=${version.value}")
6162

6263
Scala versions are defined in `.travis.yml`.
6364

64-
Cross-building with Scala.js and Scala Native is possible, see scala-xml or scala-parser-combinators for example.
65+
Cross-building with Scala.js and Scala Native is possible, see travis-test, scala-xml or scala-parser-combinators for example.
6566

6667
These additional settings are enabled by `scalaModuleSettings`:
6768
- `scalacOptions in (Compile, compile) ++= Seq("-feature", "-deprecation", "-unchecked", "-Xlint")`
6869
- A `projectName.properties` file is generated and packaged
6970
- `fork in Test := true` to work around some classpath clashes with scala-xml
70-
- POM and OSGi metadata
71+
- POM metadata
7172

7273
The following settings are also available:
7374
- `enableOptimizer` adds `-opt-inline-from:<sources>` or `-opt:l:project` or `-optimize` to `scalacOptions in (Compile, compile)`,
@@ -106,6 +107,7 @@ Tag the release and add release notes to https://github.com/scala/sbt-scala-modu
106107

107108
- Sign in to Bintray (https://bintray.com/login) or create an "Open Source" account (https://bintray.com/signup/oss)
108109
- Check if you have a repository named `sbt-plugins`. If not, create it (Name: sbt-plugins, Type: Generic).
110+
- Make sure to use Java 8
109111
- Make sure the current `HEAD` is a tagged revision. In sbt, `version` (set by sbt-git) should be according to a tag.
110112

111113
> version

src/main/scala/ScalaModulePlugin.scala

+20-18
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ object ScalaModulePlugin extends AutoPlugin {
5353
)
5454

5555
/**
56-
* Enable `-opt:l:inline`, `-opt:l:classpath` or `-optimize`, depending on the scala version.
56+
* Enable `-opt:l:inline`, `-opt:l:project` or `-optimize`, depending on the scala version.
5757
*/
5858
lazy val enableOptimizer: Setting[_] = scalacOptions in (Compile, compile) ++= {
5959
val Ver = """(\d+)\.(\d+)\.(\d+).*""".r
@@ -138,8 +138,26 @@ object ScalaModulePlugin extends AutoPlugin {
138138
)
139139
) ++ mimaSettings
140140

141+
@deprecated("use scalaModuleOsgiSettings instead", "2.2.0")
141142
lazy val scalaModuleSettingsJVM: Seq[Setting[_]] = scalaModuleOsgiSettings
142143

144+
// enables the SbtOsgi plugin and defines some default settings
145+
lazy val scalaModuleOsgiSettings: Seq[Setting[_]] = SbtOsgi.projectSettings ++ SbtOsgi.autoImport.osgiSettings ++ Seq(
146+
OsgiKeys.bundleSymbolicName := s"${organization.value}.${name.value}",
147+
OsgiKeys.bundleVersion := osgiVersion.value,
148+
149+
// Sources should also have a nice MANIFEST file
150+
packageOptions in packageSrc := Seq(Package.ManifestAttributes(
151+
("Bundle-SymbolicName", s"${organization.value}.${name.value}.source"),
152+
("Bundle-Name", s"${name.value} sources"),
153+
("Bundle-Version", osgiVersion.value),
154+
("Eclipse-SourceBundle", s"""${organization.value}.${name.value};version="${osgiVersion.value}";roots:="."""")
155+
))
156+
)
157+
158+
// a setting-transform to turn the regular version into something osgi can deal with
159+
private val osgiVersion = version(_.replace('-', '.'))
160+
143161
// adapted from https://github.com/lightbend/migration-manager/blob/0.3.0/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala#L112
144162
private def artifactExists(organization: String, name: String, scalaBinaryVersion: String, version: String, ivy: IvySbt, s: TaskStreams): Boolean = {
145163
val moduleId = ModuleID(organization, s"${name}_$scalaBinaryVersion", version)
@@ -154,7 +172,7 @@ object ScalaModulePlugin extends AutoPlugin {
154172
private val canRunMima = taskKey[Boolean]("Decides if MiMa should run.")
155173
private val runMimaIfEnabled = taskKey[Unit]("Run MiMa if mimaPreviousVersion and the module can be resolved against the current scalaBinaryVersion.")
156174

157-
private lazy val mimaSettings: Seq[Setting[_]] = MimaPlugin.mimaDefaultSettings ++ Seq(
175+
private lazy val mimaSettings: Seq[Setting[_]] = Seq(
158176
scalaModuleMimaPreviousVersion := None,
159177

160178
// We're not using `%%` here in order to support both jvm and js projects (cross version `_2.12` / `_sjs0.6_2.12`)
@@ -184,22 +202,6 @@ object ScalaModulePlugin extends AutoPlugin {
184202
(test in Test).value
185203
}
186204
)
187-
188-
// a setting-transform to turn the regular version into something osgi can deal with
189-
private val osgiVersion = version(_.replace('-', '.'))
190-
191-
private lazy val scalaModuleOsgiSettings = SbtOsgi.projectSettings ++ SbtOsgi.autoImport.osgiSettings ++ Seq(
192-
OsgiKeys.bundleSymbolicName := s"${organization.value}.${name.value}",
193-
OsgiKeys.bundleVersion := osgiVersion.value,
194-
195-
// Sources should also have a nice MANIFEST file
196-
packageOptions in packageSrc := Seq(Package.ManifestAttributes(
197-
("Bundle-SymbolicName", s"${organization.value}.${name.value}.source"),
198-
("Bundle-Name", s"${name.value} sources"),
199-
("Bundle-Version", osgiVersion.value),
200-
("Eclipse-SourceBundle", s"""${organization.value}.${name.value};version="${osgiVersion.value}";roots:="."""")
201-
))
202-
)
203205
}
204206

205207

0 commit comments

Comments
 (0)