From fe4f57d079de7692460a8f1f80cffb571cbff6a6 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Fri, 15 Feb 2019 16:09:24 -0800 Subject: [PATCH 1/4] move to sbt 1. don't support or publish for 0.13 anymore fixes #32 --- .sbtrepos | 8 ------- .travis.yml | 29 ++++++------------------ README.md | 48 +++++++++++++++++++++++++++++----------- build.sbt | 34 ++++++++-------------------- project/build.properties | 2 +- project/plugins.sbt | 5 +---- 6 files changed, 53 insertions(+), 73 deletions(-) delete mode 100644 .sbtrepos diff --git a/.sbtrepos b/.sbtrepos deleted file mode 100644 index b9e49c4..0000000 --- a/.sbtrepos +++ /dev/null @@ -1,8 +0,0 @@ -[repositories] - local - local-preloaded-ivy: file:///${sbt.preloaded-${sbt.global.base-${user.home}/.sbt}/preloaded/}, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext] - local-preloaded: file:///${sbt.preloaded-${sbt.global.base-${user.home}/.sbt}/preloaded/} - maven-central: http://repo1.maven.org/maven2/ - sonatype-public: http://oss.sonatype.org/content/repositories/public - typesafe-ivy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly - sbt-ivy-releases: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext], bootOnly diff --git a/.travis.yml b/.travis.yml index c045036..30bfb71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,34 +1,19 @@ language: scala -# Needed for openjdk6 -dist: precise -sudo: required -addons: - hosts: - - localhost - hostname: localhost.local - jdk: - - openjdk6 - -# cache stuff, hopefully shortening build times -cache: - directories: - - $HOME/.ivy2 - - $HOME/.sbt/boot - - $HOME/.sbt/launchers + - oraclejdk8 script: - # work around https://github.com/travis-ci/travis-ci/issues/9713 - - if [[ $JAVA_HOME = *java-6* ]]; then jdk_switcher use openjdk6; fi - - java -version - # also, Maven Central and Bintray are unreachable over HTTPS - - if [[ $JAVA_HOME = *java-6* ]]; then SBTOPTS="-Dsbt.override.build.repos=true -Dsbt.repository.config=./.sbtrepos"; fi - - sbt $SBTOPTS test + - sbt test before_cache: - find $HOME/.sbt -name "*.lock" | xargs rm - find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm +cache: + directories: + - $HOME/.ivy2 + - $HOME/.sbt/boot + - $HOME/.sbt/launchers notifications: email: diff --git a/README.md b/README.md index de84dc7..1f38c13 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,44 @@ # Scala modules sbt plugin -This is an sbt plugin for building Scala modules (scala-xml, -scala-parser-combinators, and so on). +This is an sbt plugin for building Scala modules. -The major benefit of the plugin is to provide automated tag-based -publishing. A release is made by pushing a tag to GitHub. Travis -then stages artifacts on Sonatype. Pressing "Close" and "Release" in -the Sonatype web UI will then send the artifacts to Maven Central. +## What modules use it? + +* [scala-async](https://github.com/scala/scala-async) +* [scala-collection-compat](https://github.com/scala/scala-collection-compat) +* [scala-java8-compat](https://github.com/scala/scala-java8-compat) +* [scala-parallel-collections](https://github.com/scala/scala-parallel-collections) +* [scala-parser-combinators](https://github.com/scala/scala-parser-combinators) +* [scala-partest](https://github.com/scala/scala-partest) +* [scala-swing](https://github.com/scala/scala-swing) +* [scala-xml](https://github.com/scala/scala-xml) + +## Why this plugin? + +Having a shared plugin reduces duplication between the above +repositories. Reducing duplication makes maintenance easier and +helps ensure consistency. + +A major feature of the plugin is automated tag-based publishing. A +release is made by pushing a tag to GitHub. Travis-CI then stages +artifacts on Sonatype. Pressing "Close" and "Release" in the Sonatype +web UI will then send the artifacts to Maven Central. + +## Branches and versions + +The main development branch is 2.x; only sbt 1 is supported there. + +sbt 0.13 support is on the legacy 1.x branch. + +Scala modules are encouraged to move to sbt 1 on their primary +development branches as soon as reasonably possible. ## Usage Add the plugin to the `project/plugins.sbt` file: ``` -addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14") +addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.0.0") ``` Then, in your `build.sbt` add: @@ -22,7 +47,7 @@ Then, in your `build.sbt` add: import ScalaModulePlugin._ scalaModuleSettings // in a multi-project build, you might want to apply these settings only to the - // main project (example: scala-parallel-collections) + // main project (see e.g. scala-parallel-collections) name := "" repoName := "" // the repo under github.com/scala/, only required if different from name @@ -35,13 +60,10 @@ scalaVersionsByJvm in ThisBuild := { val v211 = "2.11.12" val v212 = "2.12.8" val v213 = "2.13.0-M5" - // Map[JvmMajorVersion, List[(ScalaVersion, UseForPublishing)]] Map( - 6 -> List(v211 -> true), - 7 -> List(v211 -> false), - 8 -> List(v212 -> true, v213 -> true, v211 -> false), - 9 -> List(v212, v213, v211).map(_ -> false)) + 8 -> List(v211 -> true, v212 -> true, v213 -> true), + 9 -> List(v211, v212, v213).map(_ -> false)) } mimaPreviousVersion := Some("1.0.0") // enables MiMa (`None` by default, which disables it) diff --git a/build.sbt b/build.sbt index b193086..30bb4d0 100644 --- a/build.sbt +++ b/build.sbt @@ -1,31 +1,15 @@ -git.baseVersion := "1.0.0" - -versionWithGit - -name := "sbt-scala-module" - -organization := "org.scala-lang.modules" - sbtPlugin := true -// sbtVersion in Global := "0.13.1" - -// scalaVersion in Global := "2.10.3" - -// publishTo := Some(if (version.value.trim.endsWith("SNAPSHOT")) Classpaths.sbtPluginSnapshots else Classpaths.sbtPluginReleases) - -publishMavenStyle := false - -resolvers += Classpaths.sbtPluginReleases - -licenses := Seq(("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))) - -bintrayRepository := "sbt-plugins" +git.baseVersion := "1.0.0" +versionWithGit +name := "sbt-scala-module" +organization := "org.scala-lang.modules" +licenses := Seq(("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))) +resolvers += Classpaths.sbtPluginReleases +bintrayRepository := "sbt-plugins" bintrayOrganization := None +publishMavenStyle := false -// Version 0.9.1 requires Java 8 (on 6 we get NoClassDefFoundError: java/util/function/Predicate). -// We still run our plugin builds for 2.11 on Java 6, so we cannot upgrade. -addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.8.0") - +addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.4") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0") diff --git a/project/build.properties b/project/build.properties index 8e682c5..c0bab04 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.18 +sbt.version=1.2.8 diff --git a/project/plugins.sbt b/project/plugins.sbt index 8df806f..645b92f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,2 @@ -// careful upgrading this; we can't move to a version that doesn't -// work on Java 6 -addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.6.4") - +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4") From ac7e089d4bca1c5c827b80bc0074d50e8f6f2f16 Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Fri, 15 Feb 2019 16:25:19 -0800 Subject: [PATCH 2/4] wip --- build.sbt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 30bb4d0..c5692a0 100644 --- a/build.sbt +++ b/build.sbt @@ -1,11 +1,12 @@ sbtPlugin := true -git.baseVersion := "1.0.0" +git.baseVersion := "2.0.0" versionWithGit name := "sbt-scala-module" organization := "org.scala-lang.modules" licenses := Seq(("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))) + resolvers += Classpaths.sbtPluginReleases bintrayRepository := "sbt-plugins" bintrayOrganization := None From dfd3ea17d553e3cef8e2ed943128875e4d752b7d Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 16 Feb 2019 18:45:11 +0000 Subject: [PATCH 3/4] Upgrade build No need to add an sbt plugin release resolver, re-set the bintray settings (those are the defaults), and upgrade to the sbt 1.2+ way of defining an sbt plugin. --- build.sbt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index c5692a0..c583a9e 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,4 @@ -sbtPlugin := true +enablePlugins(SbtPlugin) git.baseVersion := "2.0.0" versionWithGit @@ -7,10 +7,5 @@ name := "sbt-scala-module" organization := "org.scala-lang.modules" licenses := Seq(("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0"))) -resolvers += Classpaths.sbtPluginReleases -bintrayRepository := "sbt-plugins" -bintrayOrganization := None -publishMavenStyle := false - addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.4") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0") From 3a2e5e73cec86dae049cf6f21094ae22e2b57f93 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 16 Feb 2019 18:56:54 +0000 Subject: [PATCH 4/4] Upgrade to sbt 1's (still internal) APIs Also avoid sbt's sensitive .value linter. --- src/main/scala/ScalaModulePlugin.scala | 39 ++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/main/scala/ScalaModulePlugin.scala b/src/main/scala/ScalaModulePlugin.scala index 2de8cd1..941d870 100644 --- a/src/main/scala/ScalaModulePlugin.scala +++ b/src/main/scala/ScalaModulePlugin.scala @@ -3,8 +3,12 @@ package com.lightbend.tools.scalamoduleplugin import com.typesafe.sbt.osgi.{OsgiKeys, SbtOsgi} import com.typesafe.tools.mima.plugin.MimaKeys._ import com.typesafe.tools.mima.plugin.MimaPlugin + import sbt.Keys._ -import sbt.{Def, _} +import sbt._ +import sbt.internal.librarymanagement.IvySbt +import sbt.librarymanagement.ivy.IvyDependencyResolution +import sbt.librarymanagement.{ UnresolvedWarningConfiguration, UpdateConfiguration } object ScalaModulePlugin extends AutoPlugin { val repoName = settingKey[String]("The name of the repository under github.com/scala/.") @@ -150,26 +154,18 @@ object ScalaModulePlugin extends AutoPlugin { lazy val scalaModuleSettingsJVM: Seq[Setting[_]] = scalaModuleOsgiSettings - // adapted from https://github.com/typesafehub/migration-manager/blob/0.1.6/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala#L69 + // adapted from https://github.com/lightbend/migration-manager/blob/0.3.0/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala#L112 private def artifactExists(organization: String, name: String, scalaBinaryVersion: String, version: String, ivy: IvySbt, s: TaskStreams): Boolean = { - val moduleId = new ModuleID(organization, s"${name}_$scalaBinaryVersion", version) - val moduleSettings = InlineConfiguration( - "dummy" % "test" % "version", - ModuleInfo("dummy-test-project-for-resolving"), - dependencies = Seq(moduleId)) - val ivyModule = new ivy.Module(moduleSettings) - try { - IvyActions.update( - ivyModule, - new UpdateConfiguration( - retrieve = None, - missingOk = false, - logging = UpdateLogging.DownloadOnly), - s.log) - true - } catch { - case _: ResolveException => false - } + val moduleId = ModuleID(organization, s"${name}_$scalaBinaryVersion", version) + val depRes = IvyDependencyResolution(ivy.configuration) + val module = depRes.wrapDependencyInModule(moduleId) + val reportEither = depRes.update( + module, + UpdateConfiguration() withLogging UpdateLogging.DownloadOnly, + UnresolvedWarningConfiguration(), + s.log + ) + reportEither.fold(_ => false, _ => true) } // Internal task keys for the MiMa settings @@ -185,10 +181,11 @@ object ScalaModulePlugin extends AutoPlugin { canRunMima := { val mimaVer = mimaPreviousVersion.value val s = streams.value + val ivySbt = Keys.ivySbt.value if (mimaVer.isEmpty) { s.log.warn("MiMa will NOT run because no mimaPreviousVersion is provided.") false - } else if (!artifactExists(organization.value, name.value, scalaBinaryVersion.value, mimaVer.get, ivySbt.value, s)) { + } else if (!artifactExists(organization.value, name.value, scalaBinaryVersion.value, mimaVer.get, ivySbt, s)) { s.log.warn(s"""MiMa will NOT run because the previous artifact "${organization.value}" % "${name.value}_${scalaBinaryVersion.value}" % "${mimaVer.get}" could not be resolved (note the binary Scala version).""") false } else {