Skip to content

Commit 0821ca1

Browse files
committed
use sbt-dynver, sbt-ci-release, sbt-travisci
1 parent b54be5b commit 0821ca1

File tree

3 files changed

+25
-61
lines changed

3 files changed

+25
-61
lines changed

build.sbt

Lines changed: 3 additions & 3 deletions
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

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
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")

src/main/scala/ScalaModulePlugin.scala

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,30 @@ 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
val repoName = settingKey[String]("The name of the repository under github.com/scala/.")
1517
val mimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
16-
val scalaVersionsByJvm = 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.")
1718

18-
// See https://github.com/sbt/sbt/issues/2082
19-
override def requires = plugins.JvmPlugin
19+
// depend on DynVerPlugin to allow modifying dynverGitDescribeOutput in buildSettings below
20+
override def requires = DynVerPlugin
2021

2122
override def trigger = allRequirements
2223

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

6232
val enableOptimizerInlineFrom = settingKey[String]("The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher")
@@ -73,15 +43,8 @@ object ScalaModulePlugin extends AutoPlugin {
7343
}
7444
}
7545

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

8750
/**
@@ -117,17 +80,18 @@ object ScalaModulePlugin extends AutoPlugin {
11780
// alternatively, manage the scala instance as shown at the end of this file (commented)
11881
fork in Test := true,
11982

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

130-
publishMavenStyle := true,
13195
scmInfo := Some(ScmInfo(url(s"https://github.com/scala/${repoName.value}"),s"scm:git:git://github.com/scala/${repoName.value}.git")),
13296
homepage := Some(url("http://www.scala-lang.org/")),
13397
organizationHomepage := Some(url("http://www.scala-lang.org/")),

0 commit comments

Comments
 (0)