-->

Copy a single dependency jar into a folder via bui

2019-04-14 03:51发布

问题:

During the stage task, I'd like sbt to grab the newrelic jar from the ivy repos and copy it into a folder. Ideally, the jar is configured the same way dependencies are, but not necessarily within the libraryDependencies Seq itself (as it's not a build or runtime dependency).

回答1:

You could declare a new configuration Stage. You could set libraryDependencies to the desired value in that configuration. Later your stage task could read update report and copy the files to the desired directory.

val stage = taskKey[Unit]("Stage task")

val Stage = config("stage")

val root = project.in(file(".")).configs(Stage).settings( inConfig(Stage)(Classpaths.ivyBaseSettings): _* )

libraryDependencies in Stage := Seq("com.newrelic.agent.java" % "newrelic-api" % "3.7.0")

stage := {
  (update in Stage).value.allFiles.foreach { f =>
    IO.copyFile(f, baseDirectory.value / f.getName)
  }
}

You can checkout a working example in my github repository