Gradle

Gradle NetBeans Example

Greeting.java

package com.javacodegeeks.gradle.netbeans;

/**
 *
 * @author Andres Cespedes
 * @since 1.7
 */
public class Greeting {

    public static void main(String[] args) {
        System.out.println("Hello World JCG in Gradle NetBeans");
    }
}

The last step is to set this class as Main Class, so in build.gradle script of subproject HelloProject type full name without extension. The build.gradle script may looks like this:

    // Note: "common.gradle" in the root project contains additional initialization
    //   for this project. This initialization is applied in the "build.gradle"
    //   of the root project.

    // 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.
    if (!hasProperty('mainClass')) {
        ext.mainClass = 'com.javacodegeeks.gradle.netbeans.Greeting'
    }

    dependencies {
        // TODO: Add dependencies here
        //   but note that JUnit should have already been added in parent.gradle.
        //   By default, only the Maven Central Repository is specified in
        //   parent.gradle.
        //
        // You can read more about how to add dependency here:
        //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
    }

So, make right click on subproject HelloProject then Run, the output will be this:

NetBeans Gradle Output
NetBeans Gradle Output

7. Key Points

Tips

  • Gradle NetBeans Plugin is unofficial yet, but Kelemen has done a great job.
  • In NetBeans Gradle needs a multiproject structure, is mandatory a root project to work.
  • All Gradle configuration needs to be done right in both places to ensure correctly operation, gradle build scripts and project properties.

8. Download the NetBeans Project

This was an example of Gradle NetBeansPlugin.

Download
You can download the full source code of this example here: Sign up
Tags

Andres Cespedes

Andres is a Java Software Craftsman from Medellin Colombia, who strongly develops on DevOps practices, RESTful Web Services, Continuous integration and delivery. Andres is working to improve software process and modernizing software culture on Colombia.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button