我开始了一个学习项目,熟悉Gradle,Spring和Vaadin.到目前为止,我已经在一些Spring指南的帮助下成功创建了基本的CRUD功能.
现在我想将项目导入NetBeans.我为NetBeans 安装了Gradle Support插件,并将我的存储库克隆到一个新的NetBeans项目中.
当我在NetBeans中尝试build
或bootRun
项目时,它失败了,告诉我无法找到主类.但是当我build
或者bootRun
直接从命令行使用我加载到存储库的gradle包装器时,它工作正常.
我在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
我将提到的堆栈跟踪粘贴到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不应自动添加任务".
我在build.gradle
NetBeans生成的文件中找到的这条评论给了我关键的提示:
// 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.