Pass Spring Boot jar name to Gradle Groovy script











up vote
0
down vote

favorite












I have a gradle script that runs after the SpringBoot jar file is generated:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
}


So far, the gradle script just prints a message:



println "hello world from groovy version ${GroovySystem.version}"


This works fine in my build.




gradle runScript




Task :runScript hello world from groovy version 2.4.15





What I want is something like:



println "hello world generated jar file name is ${jarFileName}"


What I want to do is pass in the SpringBoot generated jar name, or the name of the jar in build/libs/my-service-0.1.1.jar or whatever it is.



So it would print:




hello world generated jar file name is my-service-0.1.1.jar




How can I do that?



Here is what I tried:



postpackage.groovy:



println "hello world from groovy version ${GroovySystem.version}"

println "hello world from groovy version $bootJar.archiveName"


build.gradle:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
}


Here's the error:




Task :runScript FAILED
hello world from groovy version 2.4.15 Exception in thread "main"
groovy.lang.MissingPropertyException: No such property: bootJar for
class: postpackage
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:66)











share|improve this question
























  • you can configure bootJar task like bootJar{ archiveName = project.property('theFileName') } and then use commandline parameter : ./gradlew -PtheFileName="the-target-name.jar"
    – M.Ricciuti
    Nov 10 at 15:49










  • I added exactly what I am looking for
    – mikeb
    Nov 10 at 17:12










  • then try println "hello world generated jar file name is $bootJar.archiveName"
    – M.Ricciuti
    Nov 10 at 17:16










  • Exception in thread "main" groovy.lang.MissingPropertyException: No such property: bootJar for class: postpackage
    – mikeb
    Nov 10 at 17:19










  • See the edits - I used $bootJar.archiveName and ${$bootJar.archiveName}
    – mikeb
    Nov 10 at 17:28















up vote
0
down vote

favorite












I have a gradle script that runs after the SpringBoot jar file is generated:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
}


So far, the gradle script just prints a message:



println "hello world from groovy version ${GroovySystem.version}"


This works fine in my build.




gradle runScript




Task :runScript hello world from groovy version 2.4.15





What I want is something like:



println "hello world generated jar file name is ${jarFileName}"


What I want to do is pass in the SpringBoot generated jar name, or the name of the jar in build/libs/my-service-0.1.1.jar or whatever it is.



So it would print:




hello world generated jar file name is my-service-0.1.1.jar




How can I do that?



Here is what I tried:



postpackage.groovy:



println "hello world from groovy version ${GroovySystem.version}"

println "hello world from groovy version $bootJar.archiveName"


build.gradle:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
}


Here's the error:




Task :runScript FAILED
hello world from groovy version 2.4.15 Exception in thread "main"
groovy.lang.MissingPropertyException: No such property: bootJar for
class: postpackage
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:66)











share|improve this question
























  • you can configure bootJar task like bootJar{ archiveName = project.property('theFileName') } and then use commandline parameter : ./gradlew -PtheFileName="the-target-name.jar"
    – M.Ricciuti
    Nov 10 at 15:49










  • I added exactly what I am looking for
    – mikeb
    Nov 10 at 17:12










  • then try println "hello world generated jar file name is $bootJar.archiveName"
    – M.Ricciuti
    Nov 10 at 17:16










  • Exception in thread "main" groovy.lang.MissingPropertyException: No such property: bootJar for class: postpackage
    – mikeb
    Nov 10 at 17:19










  • See the edits - I used $bootJar.archiveName and ${$bootJar.archiveName}
    – mikeb
    Nov 10 at 17:28













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a gradle script that runs after the SpringBoot jar file is generated:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
}


So far, the gradle script just prints a message:



println "hello world from groovy version ${GroovySystem.version}"


This works fine in my build.




gradle runScript




Task :runScript hello world from groovy version 2.4.15





What I want is something like:



println "hello world generated jar file name is ${jarFileName}"


What I want to do is pass in the SpringBoot generated jar name, or the name of the jar in build/libs/my-service-0.1.1.jar or whatever it is.



So it would print:




hello world generated jar file name is my-service-0.1.1.jar




How can I do that?



Here is what I tried:



postpackage.groovy:



println "hello world from groovy version ${GroovySystem.version}"

println "hello world from groovy version $bootJar.archiveName"


build.gradle:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
}


Here's the error:




Task :runScript FAILED
hello world from groovy version 2.4.15 Exception in thread "main"
groovy.lang.MissingPropertyException: No such property: bootJar for
class: postpackage
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:66)











share|improve this question















I have a gradle script that runs after the SpringBoot jar file is generated:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
}


So far, the gradle script just prints a message:



println "hello world from groovy version ${GroovySystem.version}"


This works fine in my build.




gradle runScript




Task :runScript hello world from groovy version 2.4.15





What I want is something like:



println "hello world generated jar file name is ${jarFileName}"


What I want to do is pass in the SpringBoot generated jar name, or the name of the jar in build/libs/my-service-0.1.1.jar or whatever it is.



So it would print:




hello world generated jar file name is my-service-0.1.1.jar




How can I do that?



Here is what I tried:



postpackage.groovy:



println "hello world from groovy version ${GroovySystem.version}"

println "hello world from groovy version $bootJar.archiveName"


build.gradle:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
}


Here's the error:




Task :runScript FAILED
hello world from groovy version 2.4.15 Exception in thread "main"
groovy.lang.MissingPropertyException: No such property: bootJar for
class: postpackage
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:66)








java gradle groovy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 17:28

























asked Nov 10 at 15:02









mikeb

5,20622660




5,20622660












  • you can configure bootJar task like bootJar{ archiveName = project.property('theFileName') } and then use commandline parameter : ./gradlew -PtheFileName="the-target-name.jar"
    – M.Ricciuti
    Nov 10 at 15:49










  • I added exactly what I am looking for
    – mikeb
    Nov 10 at 17:12










  • then try println "hello world generated jar file name is $bootJar.archiveName"
    – M.Ricciuti
    Nov 10 at 17:16










  • Exception in thread "main" groovy.lang.MissingPropertyException: No such property: bootJar for class: postpackage
    – mikeb
    Nov 10 at 17:19










  • See the edits - I used $bootJar.archiveName and ${$bootJar.archiveName}
    – mikeb
    Nov 10 at 17:28


















  • you can configure bootJar task like bootJar{ archiveName = project.property('theFileName') } and then use commandline parameter : ./gradlew -PtheFileName="the-target-name.jar"
    – M.Ricciuti
    Nov 10 at 15:49










  • I added exactly what I am looking for
    – mikeb
    Nov 10 at 17:12










  • then try println "hello world generated jar file name is $bootJar.archiveName"
    – M.Ricciuti
    Nov 10 at 17:16










  • Exception in thread "main" groovy.lang.MissingPropertyException: No such property: bootJar for class: postpackage
    – mikeb
    Nov 10 at 17:19










  • See the edits - I used $bootJar.archiveName and ${$bootJar.archiveName}
    – mikeb
    Nov 10 at 17:28
















you can configure bootJar task like bootJar{ archiveName = project.property('theFileName') } and then use commandline parameter : ./gradlew -PtheFileName="the-target-name.jar"
– M.Ricciuti
Nov 10 at 15:49




you can configure bootJar task like bootJar{ archiveName = project.property('theFileName') } and then use commandline parameter : ./gradlew -PtheFileName="the-target-name.jar"
– M.Ricciuti
Nov 10 at 15:49












I added exactly what I am looking for
– mikeb
Nov 10 at 17:12




I added exactly what I am looking for
– mikeb
Nov 10 at 17:12












then try println "hello world generated jar file name is $bootJar.archiveName"
– M.Ricciuti
Nov 10 at 17:16




then try println "hello world generated jar file name is $bootJar.archiveName"
– M.Ricciuti
Nov 10 at 17:16












Exception in thread "main" groovy.lang.MissingPropertyException: No such property: bootJar for class: postpackage
– mikeb
Nov 10 at 17:19




Exception in thread "main" groovy.lang.MissingPropertyException: No such property: bootJar for class: postpackage
– mikeb
Nov 10 at 17:19












See the edits - I used $bootJar.archiveName and ${$bootJar.archiveName}
– mikeb
Nov 10 at 17:28




See the edits - I used $bootJar.archiveName and ${$bootJar.archiveName}
– mikeb
Nov 10 at 17:28












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Answer:



Pass the argument via the build.gradle like this:



task runScript (dependsOn: 'bootJar', type: JavaExec) {
main = 'postpackage'
classpath = sourceSets.main.runtimeClasspath
args "${bootJar.archiveName}"
}


Reference it in the script like this:



println "hello world from groovy version ${GroovySystem.version}"

println "hello world from groovy version ${args[0]}"


Works just fine:




:bootJar UP-TO-DATE :runScript hello world from groovy version 2.4.15



hello world from groovy version my-service-0.1.1.jar



BUILD SUCCESSFUL in 2s
5 actionable tasks: 1 executed, 4 up-to-date
12:36:00 PM: Task execution finished 'runScript'.






share|improve this answer





















    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',
    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%2f53240211%2fpass-spring-boot-jar-name-to-gradle-groovy-script%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Answer:



    Pass the argument via the build.gradle like this:



    task runScript (dependsOn: 'bootJar', type: JavaExec) {
    main = 'postpackage'
    classpath = sourceSets.main.runtimeClasspath
    args "${bootJar.archiveName}"
    }


    Reference it in the script like this:



    println "hello world from groovy version ${GroovySystem.version}"

    println "hello world from groovy version ${args[0]}"


    Works just fine:




    :bootJar UP-TO-DATE :runScript hello world from groovy version 2.4.15



    hello world from groovy version my-service-0.1.1.jar



    BUILD SUCCESSFUL in 2s
    5 actionable tasks: 1 executed, 4 up-to-date
    12:36:00 PM: Task execution finished 'runScript'.






    share|improve this answer

























      up vote
      0
      down vote













      Answer:



      Pass the argument via the build.gradle like this:



      task runScript (dependsOn: 'bootJar', type: JavaExec) {
      main = 'postpackage'
      classpath = sourceSets.main.runtimeClasspath
      args "${bootJar.archiveName}"
      }


      Reference it in the script like this:



      println "hello world from groovy version ${GroovySystem.version}"

      println "hello world from groovy version ${args[0]}"


      Works just fine:




      :bootJar UP-TO-DATE :runScript hello world from groovy version 2.4.15



      hello world from groovy version my-service-0.1.1.jar



      BUILD SUCCESSFUL in 2s
      5 actionable tasks: 1 executed, 4 up-to-date
      12:36:00 PM: Task execution finished 'runScript'.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Answer:



        Pass the argument via the build.gradle like this:



        task runScript (dependsOn: 'bootJar', type: JavaExec) {
        main = 'postpackage'
        classpath = sourceSets.main.runtimeClasspath
        args "${bootJar.archiveName}"
        }


        Reference it in the script like this:



        println "hello world from groovy version ${GroovySystem.version}"

        println "hello world from groovy version ${args[0]}"


        Works just fine:




        :bootJar UP-TO-DATE :runScript hello world from groovy version 2.4.15



        hello world from groovy version my-service-0.1.1.jar



        BUILD SUCCESSFUL in 2s
        5 actionable tasks: 1 executed, 4 up-to-date
        12:36:00 PM: Task execution finished 'runScript'.






        share|improve this answer












        Answer:



        Pass the argument via the build.gradle like this:



        task runScript (dependsOn: 'bootJar', type: JavaExec) {
        main = 'postpackage'
        classpath = sourceSets.main.runtimeClasspath
        args "${bootJar.archiveName}"
        }


        Reference it in the script like this:



        println "hello world from groovy version ${GroovySystem.version}"

        println "hello world from groovy version ${args[0]}"


        Works just fine:




        :bootJar UP-TO-DATE :runScript hello world from groovy version 2.4.15



        hello world from groovy version my-service-0.1.1.jar



        BUILD SUCCESSFUL in 2s
        5 actionable tasks: 1 executed, 4 up-to-date
        12:36:00 PM: Task execution finished 'runScript'.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 17:38









        mikeb

        5,20622660




        5,20622660






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240211%2fpass-spring-boot-jar-name-to-gradle-groovy-script%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

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma