切换到Gradle后,无法在NetBeans中执行调试任务

时间:2014-05-02 00:34:10

标签: java netbeans gradle netbeans-plugins

我在Netbeans中安装了Gradle-support插件,我可以很好地构建和运行该项目。当我尝试在调试模式下运行时,我得到以下输出:

Executing: gradle debug

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

BUILD SUCCESSFUL

Total time: 0.222 secs

我正在使用:

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

为什么我不能运行我的调试器?

4 个答案:

答案 0 :(得分:19)

添加类似

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

build.gradle。它会告诉Gradle插件启动应用程序时要使用的类。也许这应该可以在UI中自定义,但我现在看不到它。

答案 1 :(得分:11)

此问题的另一个解决方案是创建新的调试任务。与gradle run任务类似,您只需将以下任务添加到build.gradle文件中:

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

答案 2 :(得分:5)

Radim's answer之外,还可以在Netbeans UI中自定义mainClass参数。

enter image description here

在Netbeans gradle项目的属性中,转到"内置任务/调试",取消选中"继承"并添加" -PmainClass = aaa.bbb.ccc"参数。

我想这也应该为运行任务完成。

与运行/调试单个文件相同的想法已经将所选文件作为参数mainClass。

答案 3 :(得分:0)

我有一个similar problem并能够修复它,将选项/其他/ Gradle /任务执行/自动任务设置为“NetBeans不应自动添加任务”。