sbt/project/Settings.scala

251 lines
6.4 KiB
Scala
Raw Normal View History

2017-04-02 21:51:11 +02:00
import sbt._
import sbt.Keys._
import sbt.ScriptedPlugin._
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 {
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"),
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()
}
},
javacOptions in Keys.doc := Seq()
)
lazy val shared = javaScalaPluginShared ++ Seq(
scalaVersion := "2.12.1",
2017-04-26 14:11:38 +02:00
crossScalaVersions := Seq("2.12.1", "2.11.11", "2.10.6"),
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(
test in Test := (),
testOnly in Test := ()
)
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 := {
if (sbtScalaVersionMatch.value)
baseDirectory.value
else
baseDirectory.value / "target" / "dummy"
2017-05-02 22:06:19 +02:00
},
publish := {
if (sbtScalaVersionMatch.value)
publish.value
},
publishLocal := {
if (sbtScalaVersionMatch.value)
publishLocal.value
},
publishArtifact := {
sbtScalaVersionMatch.value && publishArtifact.value
}
)
}
2017-04-02 21:51:11 +02:00
lazy val plugin =
javaScalaPluginShared ++
2017-05-02 22:06:19 +02:00
divertThingsPlugin ++
2017-04-02 21:51:11 +02:00
withScriptedTests ++
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
}
},
scalaVersion := appConfiguration.value.provider.scalaProvider.version, // required with sbt 0.13.16-M1, to avoid cyclic references
sbtVersion := {
scalaBinaryVersion.value match {
case "2.10" => "0.13.8"
2017-08-04 16:20:03 +02:00
case "2.12" => "1.0.0-RC3"
2017-05-02 22:06:19 +02:00
case _ => sbtVersion.value
}
},
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?
// Can't figure out why configuration get lost without this in particular...
_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.")
}
}
lazy val Integration = config("it").extend(Test)
}