Martin has posted 1 posts at DZone. View Full User Profile

Why I Like Using Gradle in NetBeans IDE (Part 1)

  • submit to reddit

Greetings from Montevideo, Uruguay! My name is Martin Steffen and I use NetBeans IDE in my work as a developer. Also, I use NetBeans IDE in my career as a student. I use NetBeans IDE for all my projects and always have installed the latest NetBeans IDE version (waiting for the new support of HTML5 :) in NetBeans IDE 7.3).

In general, I love to research new technologies and now Gradle is my point of interest. Currently I am developing a web application with Gradle, while using the Gradle Jetty plugin, (, and the build.gradle is the following:

The NetBeans Gradle plugin has everything needed to develop this project:

To develop the project with Gradle and NetBeans IDE, I follow the steps below:

  1. Open the NetBeans Terminal window (Window | Output | Terminal) and run "gradle jettyRun", as you can see here:

  2. Right-click the project node in the Projects window and choose "build", as you can see here:

  3. Go to your browser and see your running application!
  4. End of development cycle. :)

When I modify JSP pages, and static resources (HTML/JS/CSS), I don't need to rebuild the project because you see the changes in the browser instantly. When I modify a Java class, I only need to re-build the project (but don't need to stop Jetty), that is, when building the project Jetty automatically redeploys the app for you.

Interesting features:

  • static resources (HTML/JS/CSS) are refreshed instantly, as stated above, which makes me feel productive
  • redeploying in Jetty when building the project
  • the project dependencies are shows in the Projects window

Features I would like the plugin to have:

  • Open the browser when running a project; if it is not very difficult to implement this would be good to have.
  • Enable version control when right-clicking a project. The version control is disabled for Gradle projects as you can see in the second image above, while for Ant projects it is enabled, as you can see below:

  • Automatically build a project on saving. In Ant projects, you can check the option "Compile on Save" as you can see below:

  • Glassfish embedded tasks (similar to the Jetty tasks, for developing full JavaEE applications, though this feature is more for the Gradle team, perhaps.
Published at DZone with permission of its author, Martin Steffen.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Hans Dockter replied on Thu, 2012/10/25 - 5:32am

Thanks for very interesting posting and to learn how well the Gradle Netbeans plugins is suiting you. I also like the idea of an embedded Glassfish plugin. Would you mind sharing this as an 'Idea' in our forums:

Attila Kelemen replied on Thu, 2012/10/25 - 8:20am

Thank you for the article. It is nice to see that the Gradle plugin is being used for something that it was not explicitly planned for. Anyway, I would like to answer to the wishes related to the Gradle plugin:

  • Open the browser when running a project...: Opening the browser is simple to implement but with what starting page should it be opened with? And on what condition should the browser be opened (e.g.: when running "jettyRun" task)? (not in the latest release (1.1.4) yet but in the current master branch: the plugin makes lines containing URLs a link to that URL opening the external browser).
  • Enable version control when right-clicking a project...: It was already added in the latest version of the plugin.
  • Automatically build a project on saving...: It is an interesting problem. The plugin currently relies on gradle for every task it does (build, run, etc.). I'm not confident enough to compile a single file bypassing Gradle, so if automatic compilation is implemented, I would do it by simply starting "classes" task in the background. It might worth a try if it is efficient enough to be useful. Since the daemon is rather quick in incremental compilation once already up and running, it might be possible.
  • Glassfish embedded tasks...: It is already possible to define and execute custom tasks for the plugin, so if you have a Gradle task, you can add it to the project's pop-up. Probably, I should add a manual/tutorial for the plugin.


Douglas Maxwell replied on Tue, 2012/11/06 - 10:58am

This is probably not the right place for this question . 

Anyway .

Is NbGradleProjectFactory threadsafe? 

What happens around lines 33,34 when a CounterCloser decrements the count to zero (line 137) and decides to remove the counter from the map but hasn't actual removed it before the current thread increments the count and checks the map for the existence of the soon to be removed counter?

Attila Kelemen replied on Thu, 2012/11/08 - 3:27pm in response to: Douglas Maxwell

Thank you for the catch. The code is not thread-safe. Although it cannot cause a bug because currently this method and the close() are never called concurrently (they are always from NbGradleProject.PROJECT_PROCESSOR which is single threaded). Anyway, this should be fixed.

Next time please file an issue instead because I might not notice here.

Anyway, if you are wondering why I didn't use a simple lock instead: No real reason, just for fun. I like to play with concurrency and I thought there is not much to lose if I screw it here (as I sadly did). Obviously, I should have been more careful.

Douglas Maxwell replied on Thu, 2012/11/08 - 4:39pm in response to: Attila Kelemen

Hi Attila

It was just something that caught my eye that is all. 

 I'll be sure to file an issue the next time if I come across any bugs.



Matt Coleman replied on Fri, 2013/01/18 - 1:35am

Gradles indeed is so useful...i use it if i can

buffalo freelance website designer 

Mark Nguyen replied on Mon, 2013/07/15 - 2:50am

Thanks for very interesting posting and to learn how well the Gradle Netbeans plugins is suiting you. I also like the idea of an embedded Glassfish plugin. pain management care 

Cata Nic replied on Mon, 2013/09/02 - 7:34am

 The Gradle solution can be a good way to manage the problems into a very efficient way. This is a very efficient solution and deserve more attention.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.