title: Gradle sourceCompatibility has no effect to subprojects
body: <p>I have Java 6 and 7 installed on my machine. Gradle uses 1.7 (checked using <code>gradle -v</code>). But I need to compile my code to be compatible with Java 1.6. As far as I understand the documentation I can use the <code>sourceCompatibility</code> property to do so (and indirectly the <code>targetCompatibility</code> which defaults to the  <code>sourceCompatibility</code>).</p>
  
  <p>So I added the following line to my build file (on the root level, not in any closure):</p>
  
  <pre><code>sourceCompatibility = 1.6
  </code></pre>
  
  <p>(to be sure I also added the <code>targetCompatibility = 1.6</code> in some trials, but that should not make a difference)</p>
  
  <p>To check whether the result was actually compatible with 1.6 I unzipped the resulting jar, <code>cd</code> into the <code>WEB-INF/classes</code> folder and used <code>javap -verbose</code> on the first <code>.class</code> file I encountered. But no matter whether I set the target compatibility or whether I used 1.5 instead of 1.6 or whether I specified it as string (<code>'1.6'</code>), each time the result of javap was</p>
  
  <pre><code>minor version: 0
  major version: 51
  </code></pre>
  
  <p>Afaik this means it is Java 1.7 Bytecode, which is wrong.</p>
  
  <p>Any ideas why the <code>sourceCompatibility</code>-setting doesn't work? Or is <code>javap</code> not the correct way to check the compatibility?</p>
  
  <p><strong>UPDATE:</strong>
  Yes, this is actually a multi-project build but I only checked one of the subprojects' build results. In this subproject's build file I made the mentioned changes to be sure they are actually applied. In addition, I added the following in the root project's build file (as @Vidya proposed as well):</p>
  
  <pre><code>allprojects {
      sourceCompatibility = 1.6
      targetCompatibility = 1.6
  }
  </code></pre>
  
  <p>But this didn't help either.</p>
  
  <p><strong>UPDATE 2:</strong>
  I checked the setting of sourceCompatibility with this snippet in the relevant build.gradle files:</p>
  
  <pre><code>compileJava.doFirst {
      println "source compatibility " + sourceCompatibility
  }
  </code></pre>
  
  <p>It revealed that my sourceCompatibility is set to 1.7 although I tried to set it to 1.6. When I extracted the simplest subproject and built in on its own the sourceCompatibility is set correctly and the Java Byte code is compatible to 1.6. However, even this sub-project uses the wrong sourceCompatibility when used in the multi project build.</p>
  
  <p>BTW: The plugins I use in some of the sub projects are: <code>java</code>, <code>war</code>, <code>jetty</code>, <code>gwt</code></p>
  
  <p><strong>UPDATE 3:</strong>
  I changed the built scripts to just use the java plugin (and thus just construct some jars) and removed the usage of the <code>war</code>, <code>jetty</code> and <code>gwt</code> plugin. But still all the projects are set to sourceCompatibility 1.7 despite me setting it in the <code>allprojects</code> section and in some of the sub projects. All that is left now in the build scripts is the declaration of some decencies (maven, files and other sub projects), the declaration of the repositories to use, the declaration of some others tasks (that the build-task does not depend on, so it shouldn't be affected) and the configuration of the manifest file for the created jar files (I add a specification and an implementation version and title to the manifest file). </p>
  
  <p>I don't see how any of that would affect the sourceCompatibility setting.</p>