Netbeans 11 Gradle Project does not run gradle on save

2.1k Views Asked by At

I have just installed Netbeans 11.1 and when I save one of my Java files, Netbeans does not start a gradle build automatically. This used to work in Netbeans 8.2.

I have installed nb-javac and have also tried the newest Beta version to no avail.

Is this a known bug or do I need to reconfigure something when going from NB 8.2 to 11.1?

2

There are 2 best solutions below

4
On

(This is only an explanation rather than a solution to your problem.)

First, Compile on Save is an option which is set or unset at the individual project level, rather than at the global level. So for a NetBeans Gradle project, select Properties > Build > Compile to view the setting for the Compile on Save checkbox. For that checkbox, note that:

  • It is unchecked by default, so there will not be an automatic Gradle build when you save a project file.
  • It is disabled, so you cannot trigger a build whenever you save a project file.

    GradleCompileOnSave

The problem persists in the latest beta of NetBeans 11.2.

I don't see a bug report for this issue, so perhaps you can raise one? Click the Log In button to sign up first if necessary.

That said, there is a related issue which may explain why the check box cannot be enabled. See closed bug NETBEANS-680 Erroneous Gradle Compile-on-Save activity which relates to Gradle projects using version 9.0 of NetBeans. Apparently there were spurious and unwanted compile-on-save runs being triggered even though Compile on Save was unchecked. Perhaps the feature has been deliberately disabled for Gradle projects because of that issue, though that is just speculation on my part.

Also see the GitHub page for the Gradle plugin. Comments from the NetBeans team for NETBEANS-680 suggest that the problem was with the plugin rather than NetBeans. That said, if NetBeans is offering functionality that cannot be enabled (i.e Compile on Save), it is definitely a NetBeans issue regardless of the underlying cause.

Finally, note that you can configure the Gradle plugin using Tools > Options > Java > Gradle, but I dodn't see any options there that would help with this issue.

0
On

Still the same case with Netbeans 20

In my case it is a web project and I want to compile and deploy the files automatically when saved. The Gradle task here to call is "explodeWar". Afaik there is unfortunately no shortcut option for gradle tasks in Netbeans, so you need to lanch the task manually with the menu each time! :(

Here is my method to solve it:

  1. Configure it

From the project menu > Run Gradle > Tasks... , create a custom gradle command named here "deployOnSave" "description"

Notice to the "-t" before the task name which means run continuously

  1. Use it

Run the new task "deployOnSave" The build animation starts in the bottom status line and in the output window you can see

cd C:\dev\webapps\Foo-Project; .\gradlew.bat --configure-on-demand -w --continuous -x check explodedWar
Configuration on demand is an incubating feature.

Waiting for changes to input files... (ctrl-d then enter to exit)

And from now you can have your task called automatically !