I'm trying to port Codename One client builds which are very customized ant scripts to work with gradle. When you run a Codename One app on the simulator you aren't running the apps main class but rather something like:
java -classpath CodenameOneJarList com.codename1.impl.javase.Simulator nameOfTheMainClassForTheApp
To do this in gradle I edited the basic build script as such:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "com.codename1.impl.javase.Simulator"
// for netbeans
ext.mainClass = 'com.codename1.impl.javase.Simulator'
Then at the bottom I did this:
run {
args 'com.mycompany.myapp.Main'
}
This worked as expected and launched the simulator when pressing run in the IDE (NetBeans). I'm not sure if this is the "right thing" to do though and if it will work in other IDE's.
Then when I tried launching in the debugger the arguments weren't passed since I'm guessing the run
target wasn't invoked?
I tried doing this:
debug {
args 'com.mycompany.myapp.Main'
}
Which obviously failed. I'm not exactly sure where to pass arguments to the debugger?
Is this standardized by gradle?
Am I in the right direction regarding argument passing?
What does the "run" declarative syntax map to? How do I find the other potential declarative block types?
Unfortunately googling for basics like run/debug doesn't result in something useful.
The run
section in your build.gradle is DSL added to your project from the application
plugin you applied. Here is more information about the plugin. As you will have noticed, the application plugin is really geared towards producing a runnable jar, distributing and executing it - not so much for debugging and has no support for that.
To start a java process from Gradle, you can use a JavaExec
task, and any arbitrary JVM arguments using the args
field, including but not limited to debug options.
You could do something like:
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'package.Main' //class to run
// add debug arguments as required, for example:
args '-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8888,suspend=n'
}
run gradle runApp
to start your application in debug mode and then attach your IDE. Not being familiar enough with Netbeans, I can't comment on how to attach Netbeans to a debug java process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With