How can I get the path to the current target directory in my build.sbt Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow to get sbteclipse working with Scala 2.9creating and using standalone scalaz jar without sbtscala sbt - how to configure target directory structure?How to build an Uber JAR (Fat JAR) using SBT within IntelliJ IDEA?sbt runtime classPath does not match compile classPath, causes java.lang.NoClassDefFoundErrorIs there a way to specify an alternate location for sbt to look for build config via the command line?SBT: How to refer to other project source code in build.sbt?How to use Environment Variables in build.sbt?Getting filename only from Scala/ PlayError: not found: value SparkSession
If A makes B more likely then B makes A more likely"
What LEGO pieces have "real-world" functionality?
How do you clear the ApexPages.getMessages() collection in a test?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
What do you call the holes in a flute?
Jazz greats knew nothing of modes. Why are they used to improvise on standards?
Is it possible to ask for a hotel room without minibar/extra services?
Should you tell Jews they are breaking a commandment?
Antler Helmet: Can it work?
Blender game recording at the wrong time
Do working physicists consider Newtonian mechanics to be "falsified"?
Passing functions in C++
Complexity of many constant time steps with occasional logarithmic steps
Working around an AWS network ACL rule limit
Unexpected result with right shift after bitwise negation
Did the new image of black hole confirm the general theory of relativity?
Problem when applying foreach loop
What items from the Roman-age tech-level could be used to deter all creatures from entering a small area?
How to say that you spent the night with someone, you were only sleeping and nothing else?
Geometric mean and geometric standard deviation
How do I automatically answer y in bash script?
Stars Make Stars
Why does tar appear to skip file contents when output file is /dev/null?
Can I throw a longsword at someone?
How can I get the path to the current target directory in my build.sbt
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow to get sbteclipse working with Scala 2.9creating and using standalone scalaz jar without sbtscala sbt - how to configure target directory structure?How to build an Uber JAR (Fat JAR) using SBT within IntelliJ IDEA?sbt runtime classPath does not match compile classPath, causes java.lang.NoClassDefFoundErrorIs there a way to specify an alternate location for sbt to look for build config via the command line?SBT: How to refer to other project source code in build.sbt?How to use Environment Variables in build.sbt?Getting filename only from Scala/ PlayError: not found: value SparkSession
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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?
scala sbt
add a comment |
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?
scala sbt
add a comment |
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?
scala 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?
scala sbt
scala sbt
asked Mar 8 at 14:53
Florian BaierlFlorian Baierl
7571929
7571929
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
How would I call that in mybuild.sbt
?
– Florian Baierl
Mar 8 at 15:09
@FlorianBaierl check the update
– Ivan Stanislavciuc
Mar 8 at 15:25
Is it really necessary to call local variables in SBT "value"?
– Andrey Tyukin
Mar 8 at 15:33
:) no. Used IDEA for a value extraction. Btw, just failed an interview and one the points was "bad variable naming"
– Ivan Stanislavciuc
Mar 8 at 15:36
Uhm... Yeah... My condolences. I think this answer could be improved significantly by removing all the strange stuff withtaskKey
s, and simply replacing it byval targetFile: File = (Compile / packageBin / artifactPath).value
.
– Andrey Tyukin
Mar 8 at 15:39
|
show 3 more comments
In most recent 1.x style, it should be something like
val targetFile: File = (Compile / packageBin / artifactPath).value
This does not compilebuild.sbt:52: error:
value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting. val targetFile: File = (Compile / packageBin / artifactPath).value`
– Ivan Stanislavciuc
Mar 8 at 15:46
@IvanStanislavciuc Exactly. Just like you cannot useval
s anddef
s outside of class / object / package-object definitions in ordinary scala code. I assume that this is clear, and don't see any reason to point it out every time. Global structure of SBT's build files is not the topic of the question.
– Andrey Tyukin
Mar 8 at 15:48
1
this works in a task definition body, indeed.
– Ivan Stanislavciuc
Mar 8 at 15:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065716%2fhow-can-i-get-the-path-to-the-current-target-directory-in-my-build-sbt%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
How would I call that in mybuild.sbt
?
– Florian Baierl
Mar 8 at 15:09
@FlorianBaierl check the update
– Ivan Stanislavciuc
Mar 8 at 15:25
Is it really necessary to call local variables in SBT "value"?
– Andrey Tyukin
Mar 8 at 15:33
:) no. Used IDEA for a value extraction. Btw, just failed an interview and one the points was "bad variable naming"
– Ivan Stanislavciuc
Mar 8 at 15:36
Uhm... Yeah... My condolences. I think this answer could be improved significantly by removing all the strange stuff withtaskKey
s, and simply replacing it byval targetFile: File = (Compile / packageBin / artifactPath).value
.
– Andrey Tyukin
Mar 8 at 15:39
|
show 3 more comments
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.
How would I call that in mybuild.sbt
?
– Florian Baierl
Mar 8 at 15:09
@FlorianBaierl check the update
– Ivan Stanislavciuc
Mar 8 at 15:25
Is it really necessary to call local variables in SBT "value"?
– Andrey Tyukin
Mar 8 at 15:33
:) no. Used IDEA for a value extraction. Btw, just failed an interview and one the points was "bad variable naming"
– Ivan Stanislavciuc
Mar 8 at 15:36
Uhm... Yeah... My condolences. I think this answer could be improved significantly by removing all the strange stuff withtaskKey
s, and simply replacing it byval targetFile: File = (Compile / packageBin / artifactPath).value
.
– Andrey Tyukin
Mar 8 at 15:39
|
show 3 more comments
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.
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.
edited Mar 8 at 15:57
answered Mar 8 at 15:04
Ivan StanislavciucIvan Stanislavciuc
1,680411
1,680411
How would I call that in mybuild.sbt
?
– Florian Baierl
Mar 8 at 15:09
@FlorianBaierl check the update
– Ivan Stanislavciuc
Mar 8 at 15:25
Is it really necessary to call local variables in SBT "value"?
– Andrey Tyukin
Mar 8 at 15:33
:) no. Used IDEA for a value extraction. Btw, just failed an interview and one the points was "bad variable naming"
– Ivan Stanislavciuc
Mar 8 at 15:36
Uhm... Yeah... My condolences. I think this answer could be improved significantly by removing all the strange stuff withtaskKey
s, and simply replacing it byval targetFile: File = (Compile / packageBin / artifactPath).value
.
– Andrey Tyukin
Mar 8 at 15:39
|
show 3 more comments
How would I call that in mybuild.sbt
?
– Florian Baierl
Mar 8 at 15:09
@FlorianBaierl check the update
– Ivan Stanislavciuc
Mar 8 at 15:25
Is it really necessary to call local variables in SBT "value"?
– Andrey Tyukin
Mar 8 at 15:33
:) no. Used IDEA for a value extraction. Btw, just failed an interview and one the points was "bad variable naming"
– Ivan Stanislavciuc
Mar 8 at 15:36
Uhm... Yeah... My condolences. I think this answer could be improved significantly by removing all the strange stuff withtaskKey
s, and simply replacing it byval targetFile: File = (Compile / packageBin / artifactPath).value
.
– Andrey Tyukin
Mar 8 at 15:39
How would I call that in my
build.sbt
?– Florian Baierl
Mar 8 at 15:09
How would I call that in my
build.sbt
?– Florian Baierl
Mar 8 at 15:09
@FlorianBaierl check the update
– Ivan Stanislavciuc
Mar 8 at 15:25
@FlorianBaierl check the update
– Ivan Stanislavciuc
Mar 8 at 15:25
Is it really necessary to call local variables in SBT "value"?
– Andrey Tyukin
Mar 8 at 15:33
Is it really necessary to call local variables in SBT "value"?
– Andrey Tyukin
Mar 8 at 15:33
:) no. Used IDEA for a value extraction. Btw, just failed an interview and one the points was "bad variable naming"
– Ivan Stanislavciuc
Mar 8 at 15:36
:) no. Used IDEA for a value extraction. Btw, just failed an interview and one the points was "bad variable naming"
– Ivan Stanislavciuc
Mar 8 at 15:36
Uhm... Yeah... My condolences. I think this answer could be improved significantly by removing all the strange stuff with
taskKey
s, and simply replacing it by val targetFile: File = (Compile / packageBin / artifactPath).value
.– Andrey Tyukin
Mar 8 at 15:39
Uhm... Yeah... My condolences. I think this answer could be improved significantly by removing all the strange stuff with
taskKey
s, and simply replacing it by val targetFile: File = (Compile / packageBin / artifactPath).value
.– Andrey Tyukin
Mar 8 at 15:39
|
show 3 more comments
In most recent 1.x style, it should be something like
val targetFile: File = (Compile / packageBin / artifactPath).value
This does not compilebuild.sbt:52: error:
value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting. val targetFile: File = (Compile / packageBin / artifactPath).value`
– Ivan Stanislavciuc
Mar 8 at 15:46
@IvanStanislavciuc Exactly. Just like you cannot useval
s anddef
s outside of class / object / package-object definitions in ordinary scala code. I assume that this is clear, and don't see any reason to point it out every time. Global structure of SBT's build files is not the topic of the question.
– Andrey Tyukin
Mar 8 at 15:48
1
this works in a task definition body, indeed.
– Ivan Stanislavciuc
Mar 8 at 15:56
add a comment |
In most recent 1.x style, it should be something like
val targetFile: File = (Compile / packageBin / artifactPath).value
This does not compilebuild.sbt:52: error:
value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting. val targetFile: File = (Compile / packageBin / artifactPath).value`
– Ivan Stanislavciuc
Mar 8 at 15:46
@IvanStanislavciuc Exactly. Just like you cannot useval
s anddef
s outside of class / object / package-object definitions in ordinary scala code. I assume that this is clear, and don't see any reason to point it out every time. Global structure of SBT's build files is not the topic of the question.
– Andrey Tyukin
Mar 8 at 15:48
1
this works in a task definition body, indeed.
– Ivan Stanislavciuc
Mar 8 at 15:56
add a comment |
In most recent 1.x style, it should be something like
val targetFile: File = (Compile / packageBin / artifactPath).value
In most recent 1.x style, it should be something like
val targetFile: File = (Compile / packageBin / artifactPath).value
edited Mar 8 at 16:35
answered Mar 8 at 15:42
Andrey TyukinAndrey Tyukin
30.7k42352
30.7k42352
This does not compilebuild.sbt:52: error:
value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting. val targetFile: File = (Compile / packageBin / artifactPath).value`
– Ivan Stanislavciuc
Mar 8 at 15:46
@IvanStanislavciuc Exactly. Just like you cannot useval
s anddef
s outside of class / object / package-object definitions in ordinary scala code. I assume that this is clear, and don't see any reason to point it out every time. Global structure of SBT's build files is not the topic of the question.
– Andrey Tyukin
Mar 8 at 15:48
1
this works in a task definition body, indeed.
– Ivan Stanislavciuc
Mar 8 at 15:56
add a comment |
This does not compilebuild.sbt:52: error:
value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting. val targetFile: File = (Compile / packageBin / artifactPath).value`
– Ivan Stanislavciuc
Mar 8 at 15:46
@IvanStanislavciuc Exactly. Just like you cannot useval
s anddef
s outside of class / object / package-object definitions in ordinary scala code. I assume that this is clear, and don't see any reason to point it out every time. Global structure of SBT's build files is not the topic of the question.
– Andrey Tyukin
Mar 8 at 15:48
1
this works in a task definition body, indeed.
– Ivan Stanislavciuc
Mar 8 at 15:56
This does not compile
build.sbt:52: error:
value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting. val targetFile: File = (Compile / packageBin / artifactPath).value`– Ivan Stanislavciuc
Mar 8 at 15:46
This does not compile
build.sbt:52: error:
value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting. val targetFile: File = (Compile / packageBin / artifactPath).value`– Ivan Stanislavciuc
Mar 8 at 15:46
@IvanStanislavciuc Exactly. Just like you cannot use
val
s and def
s outside of class / object / package-object definitions in ordinary scala code. I assume that this is clear, and don't see any reason to point it out every time. Global structure of SBT's build files is not the topic of the question.– Andrey Tyukin
Mar 8 at 15:48
@IvanStanislavciuc Exactly. Just like you cannot use
val
s and def
s outside of class / object / package-object definitions in ordinary scala code. I assume that this is clear, and don't see any reason to point it out every time. Global structure of SBT's build files is not the topic of the question.– Andrey Tyukin
Mar 8 at 15:48
1
1
this works in a task definition body, indeed.
– Ivan Stanislavciuc
Mar 8 at 15:56
this works in a task definition body, indeed.
– Ivan Stanislavciuc
Mar 8 at 15:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065716%2fhow-can-i-get-the-path-to-the-current-target-directory-in-my-build-sbt%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown