Oops Null Pointer

Java programming related

Gradle sourceCompatibility with Eclipse

Recently I had an issue setting the sourceCompatibility for the eclipse plugin. Turns out you can only set this property after the Java plugin has been applied. If you don’t you get a ClassCastException (BigDecimal to JavaVersion).

You can typically set the sourceCompatibility property directly the file after the apply for the Java plugin (but before the eclipse plugin) but in my build I’m using a common build file to apply plugins so I don’t have the flexibility to do that.

Instead I need to use a plugin callback as follows:


plugins.withType(JavaPlugin) {
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: