简体   繁体   中英

How can I get the path to the current target directory in my build.sbt

In my build.sbt I want to know the current target file. Something like this:

val targetFile = ??? // /home/fbaierl/Repos/kcc/scala/com.github.fbaierl/target/scala-2.12/myapplication_2.12-1.2.3-SNAPSHOT.jar

With target.value I only get the directory up until /target. Is there any way to get the full path to the resulting jar?

What you need is the return value of compile:package .

Run sbt "show compile:package" to see that it prints full path to the artifact you are building.

If you just need the path without building the artifact, do sbt "show Compile / packageBin / artifactPath"

In order to use this value in build.sbt , you have to define a task or setting like this

val targetFile = taskKey[File]("shows target file")

targetFile := {
  val path = artifactPath.in(packageBin).in(Compile).value
  //same as val path = (Compile / packageBin / artifactPath).value
  streams.value.log.info(path.toPath.toString)
  path
}

A value of any task in sbt cannot be directly assigned to a val like val someFile: File . You have to write your custom logic in terms of settings and tasks.

在最近的1.x风格中,它应该是类似的

  val targetFile: File = (Compile / packageBin / artifactPath).value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM