Oops Null Pointer

Java programming related

Category Archives: Gradle

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
}