【问题标题】:Cannot build Gradle project with Gradle Support plugin for NetBeans 8.1无法使用适用于 NetBeans 8.1 的 Gradle 支持插件构建 Gradle 项目
【发布时间】:2017-02-16 21:22:48
【问题描述】:

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

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

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

我研究了Gradle Support plugin's wiki on GitHub 的每一页,但找不到与我的问题相关的任何信息。

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

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 插件不应该只是调用我直接在命令行上使用的相同命令并且工作正常吗?

【问题讨论】:

    标签: java netbeans gradle


    【解决方案1】:

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

    a) 添加

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

    build.gradle

    b) 将 Options / Miscellaneous / Gradle / Task Execution / Automatic tasks 设置为“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=<QUALIFIED_CLASS_NAME>" 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.
    

    【讨论】:

      【解决方案2】:

      我在使用最新版本的 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的变化更新配置。

      【讨论】:

      • 当我为 Spring Boot Gradle 插件指定版本 1.2.8 时,我在运行 gradle 时得到一个 ModelBuildingException。我还尝试根据我在 1.3 版的发行说明中红色的内容调整build.gradle,您提供了一个链接,但结果与原始帖子中描述的相同。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-16
      • 2016-03-24
      相关资源
      最近更新 更多