Gradle Application plugin: add 'remotedebug' switch to scripts

Hi everyone -

Relatively new Gradle user here and first post. Be gentle. :stuck_out_tongue:

I am using the “Application” plugin to assemble my app, which I run on a remote Linux server. I need to remotely debug my app (via IntelliJ), which requires me to add additional flags to the JVM when I run my app.

What I’d like to do is define an optional runtime switch be added to my app’s scripts ("-remotedebug", for example) that would add on the required JVM command line arguments. So I’d like to do this:

bin/myapp -remotedebug

which would, in turn, add additional args to the JVM command line.

Thanks in advance for any pointers!
James

I found an alternative approach to what I’m trying to accomplish that suits my needs just fine. I’m including my solution here for others’ benefit:

Thanks to this very helpful Mkyong article, I have chosen to instruct Gradle’s Application plugin to generate a second startup script that passes the additional JVM arguments that I need. Here’s the magic:

task createAnotherStartupScript(type: CreateStartScripts) { 
   mainClassName = "my.main.Class"
   classpath = startScripts.classpath
   outputDir = startScripts.outputDir
   applicationName = 'customStartupScript'
   defaultJvmOpts = ["-customOpt1", "-customOpt2", "-customOpt3"]
}

applicationDistribution.into("bin") {
   duplicatesStrategy = DuplicatesStrategy.EXCLUDE
   from(createAnotherStartupScript)
   fileMode = 0755
}

This will result in the creation of a second set of startup scripts in my package’s ‘bin’ directory called “customStartupScript” (Linux) and “customStartupScript.bat” that do exactly what I need.

Hope others find this useful. Does anyone have another approach?

James