Why are class files generated by Groovy project always 1.5?


(Blaine Simpson) #1

Regardless whether I am building with Java 1.5 or 1.6, regardless what I set compileJava.targetCompatibility and compileGroovy.targetCompatibility to, the .class files generated by my project (using groovy plugin) are always 1.5 (major/minor version 49/0) and can be run with 1.5 JRE.

The starting compileJava.targetCompatibility and compileGroovy.targetCompatibility values when using the groovy plugin are both 1.6. So why does everything always come out 1.5-compatible?

According to what http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.compile.GroovyCompile.html says about compileGroovy.targetCompatibility, my .classes built with setting of 1.6 should not be executable by 1.5 but they are.

Anybody know why?

My goal is to publish 1.5-compatible jars, but I want to code to enforce that. I don’t want to depend on what looks to be unintended and possibly to-be-fixed behavior.

I’m using Gradle 1.2.


(Peter Niederwieser) #2

The target compatibility gets passed unchanged to the Groovy compiler. Depending on which Groovy version you use, the “best” it can generate is 1.5 class files though.

If you want to future-proof this, set ‘targetCompatibility’ to the desired value.