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

**URL:** <https://discuss.gradle.org/t/can-you-write-java-7-and-compile-it-to-java-6-with-gradle/3369>\
**Category:** Old Forum Archive\
**Created:** [August 8, 2012, 7:45pm UTC](https://discuss.gradle.org/t/can-you-write-java-7-and-compile-it-to-java-6-with-gradle/3369 "2012-08-08T19:45:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonard\_Ehrenfried](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/leonard_ehrenfried/32/700_2.png) [@Leonard\_Ehrenfried](https://discuss.gradle.org/u/Leonard_Ehrenfried)\
**Post date:** [August 8, 2012, 7:45pm UTC](https://discuss.gradle.org/t/can-you-write-java-7-and-compile-it-to-java-6-with-gradle/3369/1 "2012-08-08T19:45:00Z")

</div>

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:

```gradle
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
------------------------------------------------------------
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

```

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [August 9, 2012, 8:41am UTC](https://discuss.gradle.org/t/can-you-write-java-7-and-compile-it-to-java-6-with-gradle/3369/2 "2012-08-09T08:41:00Z")

</div>

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