Debugging task for gradle, equivalent to space {} for passing arguments

I am trying to create Codename One client builds that have very custom ant scripts for working with gradle. When you run the Codename One application on a simulator, you are not using the main application class, but something like:

java -classpath CodenameOneJarList com.codename1.impl.javase.Simulator nameOfTheMainClassForTheApp 

To do this, in gradle, I edited the base build of the 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 below I did the following:

 run { args 'com.mycompany.myapp.Main' } 

This worked as expected and ran the simulator when you clicked the run in the IDE (NetBeans). I am not sure if this is correct, and if it will work in other IDEs.

Then, when I tried to run in the debugger, no arguments were passed, since I assume that the run target was not called?

I tried to do this:

 debug { args 'com.mycompany.myapp.Main' } 

Which is clearly failed. I'm not quite sure where to pass arguments to the debugger?

Is this a standardized gradle?

Am I in the right direction regarding passing an argument?

What is a declarative syntax map "run"? How to find other potential types of declarative blocks?

Unfortunately, searching for keywords such as run / debug does not lead to anything useful.

+5
source share
1 answer

The run section in your build.gradle is the DSL added to your project from the application plugin that you applied. Here is more info about the plugin. As you noticed, the application plugin is really focused on creating an executable jar, its distribution and execution is not only for debugging, but also for support.

To start a java process from Gradle, you can use the JavaExec task and any arbitrary JVM arguments with args , including, but not limited to, debugging options.

You can 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 run the application in debug mode, and then attach your IDE. Without being familiar enough with Netbeans, I cannot comment on how to bind Netbeans to a Java debugging process.

+1
source

Source: https://habr.com/ru/post/1242151/


All Articles