Question

I've installed the Gradle-support plugin in Netbeans and I can build and run the project just fine. When I try to run in debug mode, I get the following output:

Executing: gradle debug

:debug
Cannot execute debug because the property "mainClass" is not defined or empty.

BUILD SUCCESSFUL

Total time: 0.222 secs

I'm using:

 Oracle Java 1.8
 Gradle 1.12
 Netbeans 8.0
 Gradle-Support 1.3.0
 LinuxMint 16

Why can't I run my debugger?

Was it helpful?

Solution

Add something like

if (!hasProperty('mainClass')) {
    ext.mainClass = 'com.foo.acme.Main'
}

to your build.gradle. It will tell Gradle plugin what class to use when starting your application. Perhaps that should be customizable in the UI but I cannot see it now.

OTHER TIPS

Another solution to this problem is to create a new debug task. Similar to the gradle run task you can just add the following task to your build.gradle file:

task debug(dependsOn: classes, type: JavaExec) {
    main = project.mainClassName
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
    workingDir = project.assetsDir
    ignoreExitValue = true
    debug = true
}

In addition to Radim's answer the way to customize the mainClass parameter in the Netbeans UI.

enter image description here

In the properties of a Netbeans gradle project go to "Built-In Tasks/Debug", unclick the "Inherit" and add "-PmainClass=aaa.bbb.ccc" to the arguments.

I guess this should also be done for the run task.

It's the same idea like run/debug single file which already take the selected file as parameter mainClass.

I had a similar problem and was able to fix it setting Options / Miscellaneous / Gradle / Task Execution / Automatic tasks to "NetBeans should not add tasks automatically".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top