无法使用NetBeans 8.1的Gradle支持插件构建Gradle项目

我开始了一个学习项目,熟悉Gradle,Spring和Vaadin。 到目前为止,我已经在一些Spring指南的帮助下成功创建了基本的CRUDfunction。

现在我想将项目导入NetBeans。 我为NetBeans安装了Gradle Support插件 ,并将我的存储库克隆到一个新的NetBeans项目中。

当我尝试在NetBeans中buildbootRun项目时,它失败了,告诉我无法找到主类。 但是当我使用我加载到存储库中的gradle包装器直接从命令行buildbootRun时,它工作正常。

我在GitHub上研究了Gradle Support插件的wiki的每一页,但找不到与我的问题相关的任何信息。

这是我尝试通过项目的上下文菜单操作Tasks / build / build在NetBeans中运行项目时得到的输出:

 Executing: gradle :build :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :findMainClass FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':findMainClass'. > Could not find property 'main' on task ':run'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 1.957 secs Build failure (see the Notifications window for stacktrace): gradle :build 

我将提到的stacktrace粘贴到Gist上。

这是我在同一个项目中从命令行执行的成功构建的输出:

 $ ./gradlew build :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :findMainClass :jar :bootRepackage :assemble :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test UP-TO-DATE :check UP-TO-DATE :build BUILD SUCCESSFUL Total time: 11.673 secs 

我真的不知道如何继续这个并且非常感谢任何提示我发现从命令行运行和从NetBeans运行时得到不同的结果我很奇怪。 不应该NetBeans插件只是调用我在命令行上直接使用的相同命令,并且工作正常吗?

我找到了两种方法来解决这个问题。

a)添加

 if (!hasProperty('mainClass')) { ext.mainClass = 'org.foo.Bar' } 

build.gradle

b)将选项/其他/ Gradle /任务执行/自动任务设置为“NetBeans不应自动添加任务”。

我在NetBeans生成的build.gradle文件中找到的这条评论给了我关键的提示:

 // NetBeans will automatically add "run" and "debug" tasks relying on the // "mainClass" property. You may however define the property prior executing // tasks by passing a "-PmainClass=" argument. // // Note however, that you may define your own "run" and "debug" task if you // prefer. In this case NetBeans will not add these tasks but you may rely on // your own implementation. 

使用最新版本的spring-boot-gradle-plugin(1.3.1.RELEASE)时出现了同样的错误。 降级到1.2.8.RELEASE后,错误消失了。

1.3.x中有一些配置更改,请参阅此处的Gradle插件: https : //github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.3-Release-Notes

也许NetBeans Gradle与命令行中的版本解析不同。 因此,您可以尝试指定版本1.2.8,或根据1.3更改更新配置。