Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't execute debug task in NetBeans after switching to Gradle

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?

like image 746
Stephen__T Avatar asked May 02 '14 00:05

Stephen__T


People also ask

How do I debug a Java Gradle project in Eclipse?

Open Eclipse and go to Run -> Debug Configurations.... Select the Remote Java Application in the list of configuration types on the left. Click the New toolbar button. In the Project field of the Connect tab, type or browse to select the project to use as a reference for the launch (for source lookup).


2 Answers

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.

like image 78
Radim Avatar answered Oct 22 '22 01:10

Radim


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
}
like image 45
Marius W Avatar answered Oct 21 '22 23:10

Marius W