Annotation Processing in Gradle

Richard Bair richard.bair at oracle.com
Thu Oct 18 13:58:01 PDT 2012


OK, I apologize up front -- this gradle script is not something you can reproduce in its entirety because some of the sources I'm building with have not been made public yet (see other email thread today on that subject). However I thought it would be good to detail what I'm up to and any Gradle master's could lend a hand if you have a moment :-)

Here is my current directory structure:

javafx/
	build-tools/
		src/
			java/
				META-INF/services/javafx.annotation.processing.Processor
				com/
				javafx/
	modules/
		base/
			src/
				build/
					com/sun/javafx/runtime/VersionInfo.java
				java/
					com/
					javafx/

Here is my settings.gradle file:

include 'build-tools', 'base', 'graphics', 'controls', 'swing', 'swt', 'web', 'fxml'
project(':base').projectDir = file('modules/base')
project(':graphics').projectDir = file('modules/graphics')
project(':controls').projectDir = file('modules/controls')
project(':swing').projectDir = file('modules/swing')
project(':swt').projectDir = file('modules/swt')
project(':web').projectDir = file('modules/web')
project(':fxml').projectDir = file('modules/fxml')


And here is a portion of my build.gradle file:

allprojects {
    apply plugin: 'java'
    repositories {
        mavenCentral()
    }
}

project(':build-tools') {
    sourceSets {
        main {
            java {
                srcDirs = ['src/java']
                exclude "META-INF/services/*"
            }
            resources {
                srcDirs = ['src/java']
                include "META-INF/services/*"
            }
        }
    }
}

project(':base') {
    sourceSets.main.java.srcDirs = ['src/java', 'src/build']
    // TODO need to transform the VersionInfo in the src/build prior to compilation
    dependencies {
        compile project(':build-tools')
    }
}

Now, my current issue is this: in build-tools, I have my annotation processor (BuilderProcessor). It also has some annotations. We use the annotations in our sources, such that we can say "@NoBuilder" or define default values for properties in constructors, etc, so that the builder annotation processor can create the right Builder implementation. So the Annotations need to be available to build-tools, and the annotation processor is also in build-tools, and base (and other modules) must both depend on build-tools (for the annotations) as well as use the annotation processor in build-tools during build time.

OK, so that goop in the project(':build-tools') block makes sure teh META-INF of the generated build-tools.jar is correct, so that hopefully the classpath is right for base, so that the annotation processor will be run.

Fine. Unfortunately I'm getting a very unhelpful error message:

Exception thrown while constructing Processor object: null

I'm not sure where the error lies, will keep digging. If anybody has an idea, let me know.

Thanks
Richard


More information about the openjfx-dev mailing list