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

痞子三分冷 提交于 2019-12-06 09:34:42

问题


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



来源:https://stackoverflow.com/questions/24024866/copy-a-single-dependency-jar-into-a-folder-via-build-sbt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!