Skip to content

Commit 0902245

Browse files
authored
Merge pull request #65 from lrytz/ci-release
use sbt-dynver, sbt-ci-release, sbt-travisci
2 parents 752edea + 40669da commit 0902245

File tree

3 files changed

+25
-61
lines changed

3 files changed

+25
-61
lines changed

Diff for: build.sbt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
enablePlugins(SbtPlugin)
22

3-
git.baseVersion := "2.0.0"
4-
versionWithGit
5-
63
name := "sbt-scala-module"
74
organization := "org.scala-lang.modules"
85
licenses := Seq(("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0")))
96

107
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.5")
8+
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
119
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.5.0")
10+
addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.2.0") // set scalaVersion and crossScalaVersions
11+
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.3.1") // set version, scmInfo, publishing settings

Diff for: project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
1+
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0")
22
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.5")

Diff for: src/main/scala/ScalaModulePlugin.scala

+21-57
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,34 @@ package com.lightbend.tools.scalamoduleplugin
33
import com.typesafe.sbt.osgi.{OsgiKeys, SbtOsgi}
44
import com.typesafe.tools.mima.plugin.MimaKeys._
55
import com.typesafe.tools.mima.plugin.MimaPlugin
6-
6+
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport.{HeaderLicense, headerLicense}
77
import sbt.Keys._
88
import sbt._
99
import sbt.internal.librarymanagement.IvySbt
1010
import sbt.librarymanagement.ivy.IvyDependencyResolution
11-
import sbt.librarymanagement.{ UnresolvedWarningConfiguration, UpdateConfiguration }
11+
import sbt.librarymanagement.{UnresolvedWarningConfiguration, UpdateConfiguration}
12+
import sbtdynver.DynVerPlugin
13+
import sbtdynver.DynVerPlugin.autoImport.dynverGitDescribeOutput
1214

1315
object ScalaModulePlugin extends AutoPlugin {
1416
object autoImport {
1517
val scalaModuleRepoName = settingKey[String]("The name of the repository under github.com/scala/.")
1618
val scalaModuleMimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
17-
val scalaModuleScalaVersionsByJvm = settingKey[Map[Int, List[(String, Boolean)]]]("For a Java major version (6, 8, 9), a list of a Scala version and a flag indicating whether to use this combination for publishing.")
1819
val scalaModuleEnableOptimizerInlineFrom = settingKey[String]("The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher.")
1920
}
2021
import autoImport._
2122

22-
// See https://github.com/sbt/sbt/issues/2082
23-
override def requires = plugins.JvmPlugin
23+
// depend on DynVerPlugin to allow modifying dynverGitDescribeOutput in buildSettings below
24+
override def requires = DynVerPlugin
2425

2526
override def trigger = allRequirements
2627

2728
// Settings in here are implicitly `in ThisBuild`
2829
override def buildSettings: Seq[Setting[_]] = Seq(
29-
scalaModuleScalaVersionsByJvm := Map.empty,
30-
31-
crossScalaVersions := {
32-
val OneDot = """1\.(\d).*""".r // 1.6, 1.8
33-
val Maj = """(\d+).*""".r // 9
34-
val javaVersion = System.getProperty("java.version") match {
35-
case OneDot(n) => n.toInt
36-
case Maj(n) => n.toInt
37-
case v => throw new RuntimeException(s"Unknown Java version: $v")
38-
}
39-
40-
val isTravis = Option(System.getenv("TRAVIS")).exists(_ == "true") // `contains` doesn't exist in Scala 2.10
41-
val isTravisPublishing = Option(System.getenv("TRAVIS_TAG")).exists(_.trim.nonEmpty)
42-
43-
val byJvm = scalaModuleScalaVersionsByJvm.value
44-
if (byJvm.isEmpty)
45-
throw new RuntimeException(s"Make sure to define `scalaVersionsByJvm in ThisBuild` in `build.sbt` in the root project, using the `ThisBuild` scope.")
46-
47-
val scalaVersions = byJvm.getOrElse(javaVersion, Nil) collect {
48-
case (v, publish) if !isTravisPublishing || publish => v
49-
}
50-
if (scalaVersions.isEmpty) {
51-
if (isTravis) {
52-
sLog.value.warn(s"No Scala version in `scalaVersionsByJvm` in build.sbt needs to be released on Java major version $javaVersion.")
53-
// Exit successfully, don't fail the (travis) build. This happens for example if `openjdk7`
54-
// is part of the travis configuration for testing, but it's not used for releasing against
55-
// any Scala version.
56-
System.exit(0)
57-
} else
58-
throw new RuntimeException(s"No Scala version for Java major version $javaVersion. Change your Java version or adjust `scalaVersionsByJvm` in build.sbt.")
59-
}
60-
scalaVersions
61-
},
6230
scalaModuleEnableOptimizerInlineFrom := "<sources>",
63-
scalaVersion := crossScalaVersions.value.head
31+
// drop # suffix from tags
32+
dynverGitDescribeOutput ~= (_.map(dv =>
33+
dv.copy(ref = sbtdynver.GitRef(dv.ref.value.split('#').head)))),
6434
)
6535

6636
/**
@@ -76,15 +46,8 @@ object ScalaModulePlugin extends AutoPlugin {
7646
}
7747
}
7848

79-
/**
80-
* Practical for multi-project builds.
81-
*/
8249
lazy val disablePublishing: Seq[Setting[_]] = Seq(
83-
publishArtifact := false,
84-
// The above is enough for Maven repos but it doesn't prevent publishing of ivy.xml files
85-
publish := {},
86-
publishLocal := {},
87-
publishTo := Some(Resolver.file("devnull", file("/dev/null")))
50+
skip in publish := true // works in sbt 1+
8851
)
8952

9053
/**
@@ -120,17 +83,18 @@ object ScalaModulePlugin extends AutoPlugin {
12083
// alternatively, manage the scala instance as shown at the end of this file (commented)
12184
fork in Test := true,
12285

123-
// maven publishing
124-
publishTo := Some(
125-
if (version.value.trim.endsWith("SNAPSHOT")) Resolver.sonatypeRepo("snapshots")
126-
else Opts.resolver.sonatypeStaging
127-
),
128-
credentials ++= {
129-
val file = Path.userHome / ".ivy2" / ".credentials"
130-
if (file.exists) List(new FileCredentials(file)) else Nil
131-
},
86+
headerLicense := Some(HeaderLicense.Custom(
87+
s"""|Scala (https://www.scala-lang.org)
88+
|
89+
|Copyright EPFL and Lightbend, Inc.
90+
|
91+
|Licensed under Apache License 2.0
92+
|(http://www.apache.org/licenses/LICENSE-2.0).
93+
|
94+
|See the NOTICE file distributed with this work for
95+
|additional information regarding copyright ownership.
96+
|""".stripMargin)),
13297

133-
publishMavenStyle := true,
13498
scmInfo := Some(ScmInfo(url(s"https://github.com/scala/${scalaModuleRepoName.value}"),s"scm:git:git://github.com/scala/${scalaModuleRepoName.value}.git")),
13599
homepage := Some(url("http://www.scala-lang.org/")),
136100
organizationHomepage := Some(url("http://www.scala-lang.org/")),

0 commit comments

Comments
 (0)