X

Geertjan's Blog

  • November 25, 2011

Gradle for NetBeans RCP

Geertjan Wielenga
Product Manager

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")
projectXml.configuration.data."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
:Paint:compileJava
[ant:javac] Note: Attempting to workaround javac bug #6512707
[ant:javac]
[ant:javac]
[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 com.sun.tools.javac.util.DefaultFileManager.getFileForOutput(DefaultFileManager.java:1058)
[ant:javac]

at com.sun.tools.javac.util.DefaultFileManager.getFileForOutput(DefaultFileManager.java:1034)
[ant:javac]

at com.sun.tools.javac.processing.JavacFiler.getResource(JavacFiler.java:434)
[ant:javac]

at org.openide.filesystems.annotations.LayerBuilder.validateResource(LayerBuilder.java:352)
[ant:javac]

at org.openide.filesystems.annotations.LayerBuilder$File.verifyBundleKey(LayerBuilder.java:724)
[ant:javac]

at org.openide.filesystems.annotations.LayerBuilder$File.bundlevalue(LayerBuilder.java:700)
[ant:javac]

at org.netbeans.modules.openide.windows.TopComponentProcessor.handleProcess(TopComponentProcessor.java:127)
[ant:javac]

at org.openide.filesystems.annotations.LayerGeneratingProcessor.process(LayerGeneratingProcessor.java:124)

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!

Join the discussion

Comments ( 2 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.