Gradle for NetBeans RCP

Start with the NetBeans Paint Application and do the following to build it via Gradle (i.e., no Gradle/NetBeans plugin is needed for the following steps), assuming you've set up Gradle. Do everything below in the Files or Favorites window, not in the Projects window.

  1. In the application directory "Paint Application". Create a file named "settings.gradle", with this content:
    include 'ColorChooser', 'Paint'

    Create another file in the same location, named "build.gradle", with this content:

    subprojects {
        apply plugin: "announce"
        apply plugin: "java"
        sourceSets {
            main {
                java {
                    srcDir 'src'
                resources {
                    srcDir 'src'
  2. In the module directory "Paint". Create a file named "build.gradle", with this content:
    dependencies {
        compile fileTree("$rootDir/build/public-package-jars").matching { include '**/*.jar' }
    task show << {
        configurations.compile.each { dep -> println "$dep ${dep.isFile()}" }

    Note: The above is a temporary solution, as you can see, the expectation is that the JARs are in the 'build/public-packages-jars' folder, which assumes an Ant build has been done prior to the Gradle build.

Now run 'gradle classes' in the "Paint Application" folder and everything will compile correctly.

So, this is how the Paint Application now looks:

Preferable to the second 'build.gradle' would be this, which uses the JARs found in the NetBeans Platform...

netbeansHome = '/home/geertjan/netbeans-dev-201111110600'

dependencies {
    compile files("$rootDir/ColorChooser/release/modules/ext/ColorChooser.jar") 
    def projectXml = new XmlParser().parse("nbproject/project.xml")"module-dependencies".dependency."code-name-base".each {
       if (it.text().equals('org.openide.filesystems')) {
         def dep = "$netbeansHome/platform/core/"+it.text().replace('.','-')+'.jar'
         compile files(dep)
       } else if (it.text().equals('org.openide.util.lookup') || it.text().equals('org.openide.util')) {
         def dep = "$netbeansHome/platform/lib/"+it.text().replace('.','-')+'.jar'
         compile files(dep)
       } else {
         def dep = "$netbeansHome/platform/modules/"+it.text().replace('.','-')+'.jar'
         compile files(dep)

task show << {
    configurations.compile.each { dep -> println "$dep ${dep.isFile()}" }

However, when you run 'gradle classes' with the above, you get an error like this:

geertjan@geertjan:~/NetBeansProjects/PaintApp1/Paint$ gradle classes
[ant:javac] Note: Attempting to workaround javac bug #6512707
[ant:javac] An annotation processor threw an uncaught exception.
[ant:javac] Consult the following stack trace for details.
[ant:javac] java.lang.NullPointerException
[ant:javac] 	at
[ant:javac] 	at
[ant:javac] 	at
[ant:javac] 	at org.openide.filesystems.annotations.LayerBuilder.validateResource(
[ant:javac] 	at org.openide.filesystems.annotations.LayerBuilder$File.verifyBundleKey(
[ant:javac] 	at org.openide.filesystems.annotations.LayerBuilder$File.bundlevalue(
[ant:javac] 	at
[ant:javac] 	at org.openide.filesystems.annotations.LayerGeneratingProcessor.process(

No idea why the above happens, still trying to figure it out, though it has something to do with the TopComponent (in particular, its annotations) which, if you remove it, results in a successful build. Once the above works, we can start figuring out how to use the NetBeans Maven repo instead and then the user of the plugin will be able to select whether to use local JARs or JARs from the NetBeans Maven repo.

Many thanks to Hans Dockter who put the above together with me today, via Skype!


upgrade your JDK

Posted by Bhushan N K on March 15, 2013 at 04:47 AM PDT #

upgrade your JDK

Posted by Bhushan N K on March 15, 2013 at 04:48 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« April 2014