sbt/project/Settings.scala

281 lines
7.4 KiB
Scala
Raw Normal View History

2017-04-02 21:51:11 +02:00
import sbt._
import sbt.Keys._
2017-10-26 14:53:18 +02:00
import sbt.ScriptedPlugin.autoImport.{sbtLauncher, scriptedBufferLog, ScriptedLaunchConf, scriptedLaunchOpts}
2017-04-02 21:51:11 +02:00
2017-10-20 02:48:12 +02:00
import com.lightbend.sbt.SbtProguard.autoImport._
2017-04-02 21:51:11 +02:00
import com.typesafe.sbt.pgp._
import coursier.ShadingPlugin.autoImport._
import Aliases._
2017-05-15 15:32:47 +02:00
object Settings {
val scala212 = "2.12.4"
val scala211 = "2.11.12"
val scala210 = "2.10.7"
2017-04-02 21:51:11 +02:00
lazy val scalazBintrayRepository = {
resolvers += "Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"
}
def sonatypeRepository(name: String) = {
2017-05-06 16:50:43 +02:00
resolvers += Resolver.sonatypeRepo(name)
2017-04-02 21:51:11 +02:00
}
lazy val localM2Repository = {
resolvers += Resolver.mavenLocal
}
lazy val javaScalaPluginShared = Publish.released ++ Seq(
organization := "io.get-coursier",
scalazBintrayRepository,
sonatypeRepository("releases"),
crossScalaVersions := Seq(scala212, scala211, scala210), // defined for all projects to trump sbt-doge
2017-04-02 21:51:11 +02:00
scalacOptions ++= {
val targetJvm = scalaBinaryVersion.value match {
case "2.10" | "2.11" =>
Seq("-target:jvm-1.6")
case _ =>
Seq()
}
targetJvm ++ Seq("-feature", "-deprecation")
},
javacOptions ++= {
scalaBinaryVersion.value match {
case "2.10" | "2.11" =>
Seq(
"-source", "1.6",
"-target", "1.6"
)
case _ =>
Seq()
}
},
2017-10-24 17:47:29 +02:00
javacOptions.in(Keys.doc) := Seq()
2017-04-02 21:51:11 +02:00
)
lazy val shared = javaScalaPluginShared ++ Seq(
scalaVersion := scala212,
2017-04-02 21:51:11 +02:00
libs ++= {
if (scalaBinaryVersion.value == "2.10")
Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full))
else
Seq()
}
)
lazy val pureJava = javaScalaPluginShared ++ Seq(
crossPaths := false,
autoScalaLibrary := false
)
lazy val generatePropertyFile =
2017-05-06 16:55:59 +02:00
resourceGenerators.in(Compile) += Def.task {
import sys.process._
val dir = classDirectory.in(Compile).value / "coursier"
2017-05-06 16:55:59 +02:00
val ver = version.value
2017-04-02 21:51:11 +02:00
2017-05-06 16:55:59 +02:00
val f = dir / "coursier.properties"
dir.mkdirs()
2017-05-06 16:55:59 +02:00
val p = new java.util.Properties
2017-04-02 21:51:11 +02:00
2017-05-06 16:55:59 +02:00
p.setProperty("version", ver)
p.setProperty("commit-hash", Seq("git", "rev-parse", "HEAD").!!.trim)
2017-04-02 21:51:11 +02:00
2017-05-06 16:55:59 +02:00
val w = new java.io.FileOutputStream(f)
p.store(w, "Coursier properties")
w.close()
2017-04-02 21:51:11 +02:00
2017-05-15 15:32:53 +02:00
state.value.log.info(s"Wrote $f")
2017-04-02 21:51:11 +02:00
2017-05-06 16:55:59 +02:00
Seq(f)
2017-04-02 21:51:11 +02:00
}
lazy val coursierPrefix = {
name := "coursier-" + name.value
}
lazy val scalaXmlIfNecessary = Seq(
libs ++= {
if (scalaBinaryVersion.value == "2.10") Seq()
else Seq(Deps.scalaXml)
}
)
lazy val quasiQuotesIfNecessary = Seq(
libs ++= {
if (scalaBinaryVersion.value == "2.10")
// directly depending on that one so that it doesn't get shaded
Seq(Deps.quasiQuotes)
else
Nil
}
)
lazy val noTests = Seq(
2017-10-24 17:47:29 +02:00
test.in(Test) := {},
testOnly.in(Test) := {}
2017-04-02 21:51:11 +02:00
)
lazy val utest = Seq(
libs += CrossDeps.utest.value % "test",
testFrameworks += new TestFramework("utest.runner.Framework")
)
lazy val webjarBintrayRepository = {
resolvers += "Webjars Bintray" at "https://dl.bintray.com/webjars/maven/"
}
def renameMainJar(name: String) = {
artifactName := {
val artifactName0 = artifactName.value
(sv, m, artifact) =>
if (artifact.`type` == "jar" && artifact.extension == "jar")
name
else
artifactName0(sv, m, artifact)
}
}
2017-05-02 22:06:19 +02:00
lazy val divertThingsPlugin = {
val actualSbtBinaryVersion = Def.setting(
sbtBinaryVersion.in(pluginCrossBuild).value.split('.').take(2).mkString(".")
)
val sbtPluginScalaVersions = Map(
"0.13" -> "2.10",
"1.0" -> "2.12"
)
val sbtScalaVersionMatch = Def.setting {
val sbtVer = actualSbtBinaryVersion.value
val scalaVer = scalaBinaryVersion.value
sbtPluginScalaVersions.get(sbtVer).toSeq.contains(scalaVer)
}
Seq(
baseDirectory := {
2017-10-24 17:47:29 +02:00
val baseDir = baseDirectory.value
2017-05-02 22:06:19 +02:00
if (sbtScalaVersionMatch.value)
2017-10-24 17:47:29 +02:00
baseDir
2017-05-02 22:06:19 +02:00
else
2017-10-24 17:47:29 +02:00
baseDir / "target" / "dummy"
2017-05-02 22:06:19 +02:00
},
2017-10-24 17:47:29 +02:00
// Doesn't work, the second publish or publishLocal seem not to reference the previous implementation of the key.
// This only seems to prevent ivy.xml files to be published locally anyway…
// See also similar case in Publish.scala.
// publish := Def.taskDyn {
// if (sbtScalaVersionMatch.value)
// publish
// else
// Def.task(())
// },
// publishLocal := Def.taskDyn {
// if (sbtScalaVersionMatch.value)
// publishLocal
// else
// Def.task(())
// },
2017-05-02 22:06:19 +02:00
publishArtifact := {
sbtScalaVersionMatch.value && publishArtifact.value
}
)
}
val sbt013Version = "0.13.8"
val sbt10Version = "1.0.2"
val pluginOverrideCrossScalaVersion = Seq(
crossScalaVersions := Seq(scala212, scala210)
)
2017-04-02 21:51:11 +02:00
lazy val plugin =
javaScalaPluginShared ++
2017-05-02 22:06:19 +02:00
divertThingsPlugin ++
withScriptedTests ++
2017-04-02 21:51:11 +02:00
Seq(
scriptedLaunchOpts ++= Seq(
"-Xmx1024M",
"-Dplugin.version=" + version.value,
"-Dsbttest.base=" + (sourceDirectory.value / "sbt-test").getAbsolutePath
),
scriptedBufferLog := false,
2017-05-02 22:06:19 +02:00
sbtPlugin := {
scalaBinaryVersion.value match {
case "2.10" | "2.12" => true
case _ => false
}
},
2017-10-26 14:53:18 +02:00
sbtVersion.in(pluginCrossBuild) := {
2017-05-02 22:06:19 +02:00
scalaBinaryVersion.value match {
case "2.10" => sbt013Version
case "2.12" => sbt10Version
2017-10-26 14:53:18 +02:00
case _ => sbtVersion.in(pluginCrossBuild).value
2017-05-02 22:06:19 +02:00
}
},
2017-04-02 21:51:11 +02:00
resolvers ++= Seq(
// added so that 2.10 artifacts of the other modules can be found by
// the too-naive-for-now inter-project resolver of the coursier SBT plugin
Resolver.sonatypeRepo("snapshots"),
// added for sbt-scripted to be fine even with ++2.11.x
Resolver.typesafeIvyRepo("releases")
)
)
lazy val shading =
inConfig(_root_.coursier.ShadingPlugin.Shading)(PgpSettings.projectSettings) ++
// ytf does this have to be repeated here?
2017-10-24 17:47:29 +02:00
// Can't figure out why configuration gets lost without this in particular...
2017-04-02 21:51:11 +02:00
_root_.coursier.ShadingPlugin.projectSettings ++
Seq(
shadingNamespace := "coursier.shaded",
publish := publish.in(Shading).value,
publishLocal := publishLocal.in(Shading).value,
PgpKeys.publishSigned := PgpKeys.publishSigned.in(Shading).value,
PgpKeys.publishLocalSigned := PgpKeys.publishLocalSigned.in(Shading).value
)
lazy val proguardedArtifact = Def.setting {
Artifact(
moduleName.value,
"jar",
"jar",
"standalone"
)
}
lazy val proguardedJar = Def.task {
2017-10-20 02:48:12 +02:00
val results = proguard.in(Proguard).value
2017-04-02 21:51:11 +02:00
results match {
case Seq(f) => f
case Seq() =>
throw new Exception("Found no proguarded files. Expected one.")
case _ =>
throw new Exception("Found several proguarded files. Don't know how to publish all of them.")
}
}
2017-10-24 17:47:29 +02:00
lazy val addProguardedJar = {
val extra = Def.taskDyn[Map[Artifact, File]] {
if (scalaBinaryVersion.value == "2.11")
Def.task(Map(proguardedArtifact.value -> proguardedJar.value))
else
Def.task(Map())
}
2017-10-26 14:53:18 +02:00
packagedArtifacts ++= extra.value
2017-10-24 17:47:29 +02:00
}
2017-04-02 21:51:11 +02:00
lazy val Integration = config("it").extend(Test)
}