簡體   English   中英

如何在build.sbt中獲取當前目標目錄的路徑

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

在我的build.sbt我想知道當前的目標文件。 像這樣的東西:

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

使用target.value我只獲取目錄直到/ target。 有沒有辦法獲得生成的jar的完整路徑?

你需要的是compile:package的返回值。

運行sbt "show compile:package"以查看它是否打印了您正在構建的工件的完整路徑。

如果您只需要路徑而不構建工件,請sbt "show Compile / packageBin / artifactPath"

要在build.sbt使用此值,您必須定義這樣的tasksetting

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
}

sbt中任何任務的值都不能直接分配給val,例如val someFile: File 您必須根據設置和任務編寫自定義邏輯。

在最近的1.x風格中,它應該是類似的

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM