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;








1















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?










share|improve this question




























    1















    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?










    share|improve this question
























      1












      1








      1








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 14:53









      Florian BaierlFlorian Baierl

      7571929




      7571929






















          2 Answers
          2






          active

          oldest

          votes


















          2














          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.






          share|improve this answer

























          • 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











          • 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 with taskKeys, and simply replacing it by val targetFile: File = (Compile / packageBin / artifactPath).value.

            – Andrey Tyukin
            Mar 8 at 15:39



















          1














          In most recent 1.x style, it should be something like



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





          share|improve this answer

























          • 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 vals and defs 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











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



          );













          draft saved

          draft discarded


















          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









          2














          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.






          share|improve this answer

























          • 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











          • 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 with taskKeys, and simply replacing it by val targetFile: File = (Compile / packageBin / artifactPath).value.

            – Andrey Tyukin
            Mar 8 at 15:39
















          2














          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.






          share|improve this answer

























          • 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











          • 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 with taskKeys, and simply replacing it by val targetFile: File = (Compile / packageBin / artifactPath).value.

            – Andrey Tyukin
            Mar 8 at 15:39














          2












          2








          2







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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 my build.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 with taskKeys, and simply replacing it by val 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











          • @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 with taskKeys, and simply replacing it by val 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 taskKeys, 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 taskKeys, and simply replacing it by val targetFile: File = (Compile / packageBin / artifactPath).value.

          – Andrey Tyukin
          Mar 8 at 15:39














          1














          In most recent 1.x style, it should be something like



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





          share|improve this answer

























          • 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 vals and defs 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















          1














          In most recent 1.x style, it should be something like



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





          share|improve this answer

























          • 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 vals and defs 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













          1












          1








          1







          In most recent 1.x style, it should be something like



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





          share|improve this answer















          In most recent 1.x style, it should be something like



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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 8 at 16:35

























          answered Mar 8 at 15:42









          Andrey TyukinAndrey Tyukin

          30.7k42352




          30.7k42352












          • 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 vals and defs 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











          • @IvanStanislavciuc Exactly. Just like you cannot use vals and defs 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 vals and defs 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 vals and defs 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

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved