Can you write Java 7 and compile it to Java 6 with Gradle?


(Leonard Ehrenfried) #1

For a new project I would like to use Java 7 constructs (diamond operator, multi-catch for exceptions) but I want it to be usable on Java 6 JVMs.

I see that there are the targetCompatibility and sourceCompatibility properties but when I set target to 6 and source to 7 I get the following error:

javacTask: target release 1.6 conflicts with default source release 1.7

Is what I’m trying to do at all possible?

I’m using Gradle 1.1.

------------------------------------------------------------
Gradle 1.1
------------------------------------------------------------
  Gradle build time: Tuesday, 31 July 2012 13:24:32 o'clock UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.7.0_04 (Oracle Corporation 23.0-b21)
OS: Mac OS X 10.8 x86_64

(Luke Daley) #2

Unfortunately you can’t use Java 7 language features and produce Java 6 compatible bytecode.