mirror of https://github.com/sbt/sbt.git
Add addSbtCoursier helper to sbt-lm-coursier too (#16)
This commit is contained in:
parent
6b1587302e
commit
6b1a84c563
|
|
@ -45,6 +45,7 @@ lazy val `sbt-coursier-shared` = project
|
|||
.dependsOn(`lm-coursier`)
|
||||
.settings(
|
||||
plugin,
|
||||
generatePropertyFile,
|
||||
libraryDependencies += "com.lihaoyi" %% "utest" % "0.6.4" % Test,
|
||||
testFrameworks += new TestFramework("utest.runner.Framework")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package coursier.sbtcoursiershared
|
||||
|
||||
import java.util.{Properties => JProperties}
|
||||
|
||||
object Properties {
|
||||
|
||||
private lazy val props = {
|
||||
val p = new JProperties
|
||||
try {
|
||||
p.load(
|
||||
getClass
|
||||
.getClassLoader
|
||||
.getResourceAsStream("coursier/sbtcoursier.properties")
|
||||
)
|
||||
}
|
||||
catch {
|
||||
case _: NullPointerException =>
|
||||
}
|
||||
p
|
||||
}
|
||||
|
||||
lazy val version = props.getProperty("version")
|
||||
lazy val commitHash = props.getProperty("commit-hash")
|
||||
|
||||
}
|
||||
|
|
@ -42,6 +42,8 @@ object SbtCoursierShared extends AutoPlugin {
|
|||
|
||||
type CoursierCreateLogger = coursier.lmcoursier.CreateLogger
|
||||
val CoursierCreateLogger = coursier.lmcoursier.CreateLogger
|
||||
|
||||
val sbtCoursierVersion = Properties.version
|
||||
}
|
||||
|
||||
import autoImport._
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ object CoursierPlugin extends AutoPlugin {
|
|||
|
||||
override def requires = SbtCoursierShared
|
||||
|
||||
import SbtCoursierShared.autoImport._
|
||||
|
||||
object autoImport {
|
||||
val coursierParallelDownloads = Keys.coursierParallelDownloads
|
||||
val coursierMaxIterations = Keys.coursierMaxIterations
|
||||
|
|
@ -39,9 +41,12 @@ object CoursierPlugin extends AutoPlugin {
|
|||
val coursierClassifiersArtifacts = Keys.coursierClassifiersArtifacts
|
||||
val coursierSbtClassifiersArtifacts = Keys.coursierSbtClassifiersArtifacts
|
||||
|
||||
val coursierVersion = coursier.util.Properties.version
|
||||
@deprecated("Use sbtCoursierVersion instead", "1.1.0-M9")
|
||||
val coursierVersion = sbtCoursierVersion
|
||||
|
||||
val addSbtCoursier = {
|
||||
addSbtPlugin("io.get-coursier" % "sbt-coursier" % coursierVersion)
|
||||
import sbt._
|
||||
addSbtPlugin("io.get-coursier" % "sbt-coursier" % sbtCoursierVersion)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1 @@
|
|||
addSbtPlugin {
|
||||
|
||||
val name = sys.props.getOrElse(
|
||||
"plugin.name",
|
||||
sys.error("plugin.name Java property not set")
|
||||
)
|
||||
val version = sys.props.getOrElse(
|
||||
"plugin.version",
|
||||
sys.error("plugin.version Java property not set")
|
||||
)
|
||||
|
||||
"io.get-coursier" % name % version
|
||||
}
|
||||
addSbtCoursier
|
||||
|
|
|
|||
|
|
@ -12,12 +12,18 @@ import sbt.librarymanagement.DependencyResolution
|
|||
|
||||
object LmCoursierPlugin extends AutoPlugin {
|
||||
|
||||
import SbtCoursierShared.autoImport._
|
||||
|
||||
object autoImport {
|
||||
val coursierConfiguration = taskKey[CoursierConfiguration]("General dependency management (Coursier) settings, such as the resolvers and options to use.").withRank(DTask)
|
||||
|
||||
val addSbtCoursier = {
|
||||
import sbt._
|
||||
addSbtPlugin("io.get-coursier" % "sbt-lm-coursier" % sbtCoursierVersion)
|
||||
}
|
||||
}
|
||||
|
||||
import autoImport._
|
||||
import SbtCoursierShared.autoImport._
|
||||
|
||||
|
||||
override def trigger = allRequirements
|
||||
|
|
|
|||
|
|
@ -50,5 +50,29 @@ object Settings {
|
|||
PgpKeys.publishSigned := PgpKeys.publishSigned.in(Shading).value,
|
||||
PgpKeys.publishLocalSigned := PgpKeys.publishLocalSigned.in(Shading).value
|
||||
)
|
||||
|
||||
|
||||
lazy val generatePropertyFile =
|
||||
resourceGenerators.in(Compile) += Def.task {
|
||||
import sys.process._
|
||||
|
||||
val dir = classDirectory.in(Compile).value / "coursier"
|
||||
val ver = version.value
|
||||
|
||||
val f = dir / "sbtcoursier.properties"
|
||||
dir.mkdirs()
|
||||
|
||||
val p = new java.util.Properties
|
||||
|
||||
p.setProperty("version", ver)
|
||||
p.setProperty("commit-hash", Seq("git", "rev-parse", "HEAD").!!.trim)
|
||||
|
||||
val w = new java.io.FileOutputStream(f)
|
||||
p.store(w, "sbt-coursier properties")
|
||||
w.close()
|
||||
|
||||
state.value.log.info(s"Wrote $f")
|
||||
|
||||
Seq(f)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue