gradle: change default port from 5005












4














I want to debug some JVM instances that are running at the same time. I know that I can run gradle using --debug-jvm so that the JVM will wait until I start the IDE debugger so that it connects to the JVM but it uses port 5005 by default. That's fine for debugging one instance of JVM... but if I want to debug more than one instance, I'll need to define a different port from 5005. How can I achieve this with gradle?










share|improve this question






















  • Can’t you just use integrated tools to launch in debug mode with Gradle? I know IntelliJ just lets me start a gradle process and I can still debug the code.
    – van dench
    Nov 16 at 19:23










  • Short answer: no. Long answer: No, because I'm using a script that is running many different things ending up with a gradle call.
    – eftshift0
    Nov 16 at 19:26
















4














I want to debug some JVM instances that are running at the same time. I know that I can run gradle using --debug-jvm so that the JVM will wait until I start the IDE debugger so that it connects to the JVM but it uses port 5005 by default. That's fine for debugging one instance of JVM... but if I want to debug more than one instance, I'll need to define a different port from 5005. How can I achieve this with gradle?










share|improve this question






















  • Can’t you just use integrated tools to launch in debug mode with Gradle? I know IntelliJ just lets me start a gradle process and I can still debug the code.
    – van dench
    Nov 16 at 19:23










  • Short answer: no. Long answer: No, because I'm using a script that is running many different things ending up with a gradle call.
    – eftshift0
    Nov 16 at 19:26














4












4








4


1





I want to debug some JVM instances that are running at the same time. I know that I can run gradle using --debug-jvm so that the JVM will wait until I start the IDE debugger so that it connects to the JVM but it uses port 5005 by default. That's fine for debugging one instance of JVM... but if I want to debug more than one instance, I'll need to define a different port from 5005. How can I achieve this with gradle?










share|improve this question













I want to debug some JVM instances that are running at the same time. I know that I can run gradle using --debug-jvm so that the JVM will wait until I start the IDE debugger so that it connects to the JVM but it uses port 5005 by default. That's fine for debugging one instance of JVM... but if I want to debug more than one instance, I'll need to define a different port from 5005. How can I achieve this with gradle?







java debugging gradle jvm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 at 19:20









eftshift0

4,409918




4,409918












  • Can’t you just use integrated tools to launch in debug mode with Gradle? I know IntelliJ just lets me start a gradle process and I can still debug the code.
    – van dench
    Nov 16 at 19:23










  • Short answer: no. Long answer: No, because I'm using a script that is running many different things ending up with a gradle call.
    – eftshift0
    Nov 16 at 19:26


















  • Can’t you just use integrated tools to launch in debug mode with Gradle? I know IntelliJ just lets me start a gradle process and I can still debug the code.
    – van dench
    Nov 16 at 19:23










  • Short answer: no. Long answer: No, because I'm using a script that is running many different things ending up with a gradle call.
    – eftshift0
    Nov 16 at 19:26
















Can’t you just use integrated tools to launch in debug mode with Gradle? I know IntelliJ just lets me start a gradle process and I can still debug the code.
– van dench
Nov 16 at 19:23




Can’t you just use integrated tools to launch in debug mode with Gradle? I know IntelliJ just lets me start a gradle process and I can still debug the code.
– van dench
Nov 16 at 19:23












Short answer: no. Long answer: No, because I'm using a script that is running many different things ending up with a gradle call.
– eftshift0
Nov 16 at 19:26




Short answer: no. Long answer: No, because I'm using a script that is running many different things ending up with a gradle call.
– eftshift0
Nov 16 at 19:26












2 Answers
2






active

oldest

votes


















0














You could modify GRADLE_OPTS environment variable and add standard Java debugger syntax e.g. to use port 8888:



-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8888





share|improve this answer





















  • This looked promising... but debugger fails to stop on a breakpoint I set on the project. If I use --debug-jvm and connect using port 5005, it stopped as expected. I guess there's something missing.
    – eftshift0
    Nov 16 at 19:57












  • @eftshift0 Perhaps the Gradle daemon is running in the background. Can you try with --no-daemon?
    – Karol Dowbecki
    Nov 16 at 19:57










  • that would be one option on the gladle call or an additional option on GRADLE_OPTS?
    – eftshift0
    Nov 16 at 20:00










  • @eftshift0 yes, as per docs
    – Karol Dowbecki
    Nov 16 at 20:02










  • No change, unfortunately.
    – eftshift0
    Nov 16 at 20:10



















0














In my case I wanted to debug a specific file, so I included the following code in build.gradle:



task execFile(type: JavaExec) {
main = mainClass

classpath = sourceSets.main.runtimeClasspath

if (System.getProperty('debug', 'false') == 'true') {
jvmArgs "-Xdebug", "-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y"
}

systemProperties System.getProperties()
}


and I can run with:



gradle execFile -PmainClass=com.MyClass -Dmyprop=somevalue -Ddebug=true


The custom execFile task receives:





  • -PmainClass=com.MyClass: the class with the main method I want to execute (in the script, main = mainClass)


  • -Dmyprop=somevalue: a property whose value be retrieved in the application calling System.getProperty("myprop") (in the script, systemProperties System.getProperties() was needed for that)


  • -Ddebug=true: a flag to enable debugging on port 8787 (in the script, see the if condition, and also address=8787, but the port could be changed, and this flag name also could be changed). Using suspend=y the execution is suspended until the debugger is attached to the port (if you don't want this behaviour, you could use suspend=n)


For your use case, you could try to apply the logic behind the line jvmArgs ... to your specific task (or use tasks.withType(JavaExec) { ... } to apply to all tasks of this type).



Using this solution, don't use the --debug-jvm option because you may receive an error about the property jdwp being defined twice.






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',
    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%2f53344114%2fgradle-change-default-port-from-5005%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









    0














    You could modify GRADLE_OPTS environment variable and add standard Java debugger syntax e.g. to use port 8888:



    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8888





    share|improve this answer





















    • This looked promising... but debugger fails to stop on a breakpoint I set on the project. If I use --debug-jvm and connect using port 5005, it stopped as expected. I guess there's something missing.
      – eftshift0
      Nov 16 at 19:57












    • @eftshift0 Perhaps the Gradle daemon is running in the background. Can you try with --no-daemon?
      – Karol Dowbecki
      Nov 16 at 19:57










    • that would be one option on the gladle call or an additional option on GRADLE_OPTS?
      – eftshift0
      Nov 16 at 20:00










    • @eftshift0 yes, as per docs
      – Karol Dowbecki
      Nov 16 at 20:02










    • No change, unfortunately.
      – eftshift0
      Nov 16 at 20:10
















    0














    You could modify GRADLE_OPTS environment variable and add standard Java debugger syntax e.g. to use port 8888:



    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8888





    share|improve this answer





















    • This looked promising... but debugger fails to stop on a breakpoint I set on the project. If I use --debug-jvm and connect using port 5005, it stopped as expected. I guess there's something missing.
      – eftshift0
      Nov 16 at 19:57












    • @eftshift0 Perhaps the Gradle daemon is running in the background. Can you try with --no-daemon?
      – Karol Dowbecki
      Nov 16 at 19:57










    • that would be one option on the gladle call or an additional option on GRADLE_OPTS?
      – eftshift0
      Nov 16 at 20:00










    • @eftshift0 yes, as per docs
      – Karol Dowbecki
      Nov 16 at 20:02










    • No change, unfortunately.
      – eftshift0
      Nov 16 at 20:10














    0












    0








    0






    You could modify GRADLE_OPTS environment variable and add standard Java debugger syntax e.g. to use port 8888:



    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8888





    share|improve this answer












    You could modify GRADLE_OPTS environment variable and add standard Java debugger syntax e.g. to use port 8888:



    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8888






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 16 at 19:31









    Karol Dowbecki

    16.4k82849




    16.4k82849












    • This looked promising... but debugger fails to stop on a breakpoint I set on the project. If I use --debug-jvm and connect using port 5005, it stopped as expected. I guess there's something missing.
      – eftshift0
      Nov 16 at 19:57












    • @eftshift0 Perhaps the Gradle daemon is running in the background. Can you try with --no-daemon?
      – Karol Dowbecki
      Nov 16 at 19:57










    • that would be one option on the gladle call or an additional option on GRADLE_OPTS?
      – eftshift0
      Nov 16 at 20:00










    • @eftshift0 yes, as per docs
      – Karol Dowbecki
      Nov 16 at 20:02










    • No change, unfortunately.
      – eftshift0
      Nov 16 at 20:10


















    • This looked promising... but debugger fails to stop on a breakpoint I set on the project. If I use --debug-jvm and connect using port 5005, it stopped as expected. I guess there's something missing.
      – eftshift0
      Nov 16 at 19:57












    • @eftshift0 Perhaps the Gradle daemon is running in the background. Can you try with --no-daemon?
      – Karol Dowbecki
      Nov 16 at 19:57










    • that would be one option on the gladle call or an additional option on GRADLE_OPTS?
      – eftshift0
      Nov 16 at 20:00










    • @eftshift0 yes, as per docs
      – Karol Dowbecki
      Nov 16 at 20:02










    • No change, unfortunately.
      – eftshift0
      Nov 16 at 20:10
















    This looked promising... but debugger fails to stop on a breakpoint I set on the project. If I use --debug-jvm and connect using port 5005, it stopped as expected. I guess there's something missing.
    – eftshift0
    Nov 16 at 19:57






    This looked promising... but debugger fails to stop on a breakpoint I set on the project. If I use --debug-jvm and connect using port 5005, it stopped as expected. I guess there's something missing.
    – eftshift0
    Nov 16 at 19:57














    @eftshift0 Perhaps the Gradle daemon is running in the background. Can you try with --no-daemon?
    – Karol Dowbecki
    Nov 16 at 19:57




    @eftshift0 Perhaps the Gradle daemon is running in the background. Can you try with --no-daemon?
    – Karol Dowbecki
    Nov 16 at 19:57












    that would be one option on the gladle call or an additional option on GRADLE_OPTS?
    – eftshift0
    Nov 16 at 20:00




    that would be one option on the gladle call or an additional option on GRADLE_OPTS?
    – eftshift0
    Nov 16 at 20:00












    @eftshift0 yes, as per docs
    – Karol Dowbecki
    Nov 16 at 20:02




    @eftshift0 yes, as per docs
    – Karol Dowbecki
    Nov 16 at 20:02












    No change, unfortunately.
    – eftshift0
    Nov 16 at 20:10




    No change, unfortunately.
    – eftshift0
    Nov 16 at 20:10













    0














    In my case I wanted to debug a specific file, so I included the following code in build.gradle:



    task execFile(type: JavaExec) {
    main = mainClass

    classpath = sourceSets.main.runtimeClasspath

    if (System.getProperty('debug', 'false') == 'true') {
    jvmArgs "-Xdebug", "-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y"
    }

    systemProperties System.getProperties()
    }


    and I can run with:



    gradle execFile -PmainClass=com.MyClass -Dmyprop=somevalue -Ddebug=true


    The custom execFile task receives:





    • -PmainClass=com.MyClass: the class with the main method I want to execute (in the script, main = mainClass)


    • -Dmyprop=somevalue: a property whose value be retrieved in the application calling System.getProperty("myprop") (in the script, systemProperties System.getProperties() was needed for that)


    • -Ddebug=true: a flag to enable debugging on port 8787 (in the script, see the if condition, and also address=8787, but the port could be changed, and this flag name also could be changed). Using suspend=y the execution is suspended until the debugger is attached to the port (if you don't want this behaviour, you could use suspend=n)


    For your use case, you could try to apply the logic behind the line jvmArgs ... to your specific task (or use tasks.withType(JavaExec) { ... } to apply to all tasks of this type).



    Using this solution, don't use the --debug-jvm option because you may receive an error about the property jdwp being defined twice.






    share|improve this answer


























      0














      In my case I wanted to debug a specific file, so I included the following code in build.gradle:



      task execFile(type: JavaExec) {
      main = mainClass

      classpath = sourceSets.main.runtimeClasspath

      if (System.getProperty('debug', 'false') == 'true') {
      jvmArgs "-Xdebug", "-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y"
      }

      systemProperties System.getProperties()
      }


      and I can run with:



      gradle execFile -PmainClass=com.MyClass -Dmyprop=somevalue -Ddebug=true


      The custom execFile task receives:





      • -PmainClass=com.MyClass: the class with the main method I want to execute (in the script, main = mainClass)


      • -Dmyprop=somevalue: a property whose value be retrieved in the application calling System.getProperty("myprop") (in the script, systemProperties System.getProperties() was needed for that)


      • -Ddebug=true: a flag to enable debugging on port 8787 (in the script, see the if condition, and also address=8787, but the port could be changed, and this flag name also could be changed). Using suspend=y the execution is suspended until the debugger is attached to the port (if you don't want this behaviour, you could use suspend=n)


      For your use case, you could try to apply the logic behind the line jvmArgs ... to your specific task (or use tasks.withType(JavaExec) { ... } to apply to all tasks of this type).



      Using this solution, don't use the --debug-jvm option because you may receive an error about the property jdwp being defined twice.






      share|improve this answer
























        0












        0








        0






        In my case I wanted to debug a specific file, so I included the following code in build.gradle:



        task execFile(type: JavaExec) {
        main = mainClass

        classpath = sourceSets.main.runtimeClasspath

        if (System.getProperty('debug', 'false') == 'true') {
        jvmArgs "-Xdebug", "-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y"
        }

        systemProperties System.getProperties()
        }


        and I can run with:



        gradle execFile -PmainClass=com.MyClass -Dmyprop=somevalue -Ddebug=true


        The custom execFile task receives:





        • -PmainClass=com.MyClass: the class with the main method I want to execute (in the script, main = mainClass)


        • -Dmyprop=somevalue: a property whose value be retrieved in the application calling System.getProperty("myprop") (in the script, systemProperties System.getProperties() was needed for that)


        • -Ddebug=true: a flag to enable debugging on port 8787 (in the script, see the if condition, and also address=8787, but the port could be changed, and this flag name also could be changed). Using suspend=y the execution is suspended until the debugger is attached to the port (if you don't want this behaviour, you could use suspend=n)


        For your use case, you could try to apply the logic behind the line jvmArgs ... to your specific task (or use tasks.withType(JavaExec) { ... } to apply to all tasks of this type).



        Using this solution, don't use the --debug-jvm option because you may receive an error about the property jdwp being defined twice.






        share|improve this answer












        In my case I wanted to debug a specific file, so I included the following code in build.gradle:



        task execFile(type: JavaExec) {
        main = mainClass

        classpath = sourceSets.main.runtimeClasspath

        if (System.getProperty('debug', 'false') == 'true') {
        jvmArgs "-Xdebug", "-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y"
        }

        systemProperties System.getProperties()
        }


        and I can run with:



        gradle execFile -PmainClass=com.MyClass -Dmyprop=somevalue -Ddebug=true


        The custom execFile task receives:





        • -PmainClass=com.MyClass: the class with the main method I want to execute (in the script, main = mainClass)


        • -Dmyprop=somevalue: a property whose value be retrieved in the application calling System.getProperty("myprop") (in the script, systemProperties System.getProperties() was needed for that)


        • -Ddebug=true: a flag to enable debugging on port 8787 (in the script, see the if condition, and also address=8787, but the port could be changed, and this flag name also could be changed). Using suspend=y the execution is suspended until the debugger is attached to the port (if you don't want this behaviour, you could use suspend=n)


        For your use case, you could try to apply the logic behind the line jvmArgs ... to your specific task (or use tasks.withType(JavaExec) { ... } to apply to all tasks of this type).



        Using this solution, don't use the --debug-jvm option because you may receive an error about the property jdwp being defined twice.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 27 at 13:48









        Lucas Basquerotto

        1,1101322




        1,1101322






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53344114%2fgradle-change-default-port-from-5005%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

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas