Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot build Gradle project with Gradle Support plugin for NetBeans 8.1

I started a learning project to get familiar with Gradle, Spring and Vaadin. So far, I successfully created basic CRUD functionality with the help of some Spring guides.

Now I want to import the project into NetBeans. I installed the Gradle Support plugin for NetBeans and cloned my repository into a new NetBeans project.

When I try to build or bootRun the project within NetBeans, it fails, telling me that the main class cannot be found. But when I build or bootRun directly from the command line using the gradle wrapper I loaded into the repository, it works fine.

I studied every single page of the Gradle Support plugin's wiki on GitHub but couldn't find any information relevant to my problem.

Here's the output I get when trying to run the project in NetBeans via the project's context menu action 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

I pasted the mentioned stacktrace to Gist.

And here's the output I get for the successful build executed from the command line on the very same project:

$ ./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

I have really no idea how to go on with this and would greatly appreciate any hints and I find it very odd that I get different results when running from command line and when running from within NetBeans. Shouldn't the NetBeans plugin just be calling the same commands that I use directly on the command line and that work fine?

like image 793
anothernode Avatar asked Jan 03 '16 16:01

anothernode


2 Answers

I found two ways to fix this since.

a) Adding

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

to build.gradle.

b) Setting Options / Miscellaneous / Gradle / Task Execution / Automatic tasks to "NetBeans should not add tasks automatically".

This comment I found in a build.gradle file generated by NetBeans gave me the crucial hint:

// 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.
like image 190
anothernode Avatar answered Sep 21 '22 03:09

anothernode


I got the same error when using the latest version of spring-boot-gradle-plugin (1.3.1.RELEASE). After downgrading to 1.2.8.RELEASE the error disappeared.

There has been some configuration changes in 1.3.x, see under Gradle plugin here: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.3-Release-Notes

Maybe version resolution is different in NetBeans Gradle vs. command line. So you could try specify version 1.2.8, or update the config according to the 1.3 changes.

like image 36
andersaa Avatar answered Sep 21 '22 03:09

andersaa