Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy a single dependency jar into a folder via build.sbt

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).

like image 833
bloo Avatar asked Sep 11 '25 11:09

bloo


1 Answers

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

like image 58
lpiepiora Avatar answered Sep 13 '25 05:09

lpiepiora