Gradle sourceCompatibility has no effect to subprojects(转)

I have Java 6 and 7 installed on my machine. Gradle uses 1.7 (checked using gradle -v). 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 sourceCompatibility property to do so (and indirectly the targetCompatibility which defaults to the sourceCompatibility).

So I added the following line to my build file (on the root level, not in any closure):

sourceCompatibility = 1.6

(to be sure I also added the targetCompatibility = 1.6 in some trials, but that should not make a difference)

To check whether the result was actually compatible with 1.6 I unzipped the resulting jar, cd into the WEB-INF/classes folder and used javap -verbose on the first .class 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 (‘1.6‘), each time the result of javap was

minor version: 0
major version: 51

Afaik this means it is Java 1.7 Bytecode, which is wrong.

Any ideas why the sourceCompatibility-setting doesn‘t work? Or is javap not the correct way to check the compatibility?

UPDATE: 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):

allprojects {
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
}

But this didn‘t help either.

UPDATE 2: I checked the setting of sourceCompatibility with this snippet in the relevant build.gradle files:

compileJava.doFirst {
    println "source compatibility " + sourceCompatibility
}

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.

BTW: The plugins I use in some of the sub projects are: javawarjettygwt

UPDATE 3: I changed the built scripts to just use the java plugin (and thus just construct some jars) and removed the usage of the warjetty and gwt plugin. But still all the projects are set to sourceCompatibility 1.7 despite me setting it in the allprojects 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).

I don‘t see how any of that would affect the sourceCompatibility setting.

http://stackoverflow.com/questions/21028438/gradle-sourcecompatibility-has-no-effect-to-subprojects

时间: 2024-11-09 08:29:40

Gradle sourceCompatibility has no effect to subprojects(转)的相关文章

Gradle用户指南(3)-构建Java项目

1.构建基本的Java项目 为了使用 Java 插件,添加下面代码到构建文件: build.gradle apply plugin: 'java' 这个就是 定义一个 Java 项目的全部.它会将 Java 插件应用到项目中,并且添加很多 task. Gradle 会在 src/main/java 目录下寻找产品代码,在 src/test/java 寻找测试代码 . 另外在 src/main/resources 包含了资源的 JAR 文件, src/test/resources 包含了运行测试.

Gradle方式构建Java多项目

1. 首先,安装Gradle. 简单的步骤: Prerequired: Java SDK installed 1. Dowload Gradle from: http://gradle.org/downloads 2. Set gradle home environment variable: GRADLE_HOME. Pointing to the place where the gradle binaries is 3. Add %GRADLE_HOME%\bin; to your PATH

Learn Gradle - CH 3 Java 快速入门

上一章(链接)我们主要对Gradle的脚本进行了简要的介绍,本章我们将继续学习Gradle的另外一个特性--插件(plugins). 1.插件介绍 插件是对Gradle功能的扩展,Gradle有着丰富的插件,你可以在这里搜索相关插件(传送门).本章将简要介绍Gradle的Java插件(Java plugin),这个插件会给你的构建项目添加一些任务,比如编译java类.执行单元测试和将编译的class文件打包成jar文件等. Java插件是基于约定的(约定优于配置),它在项目的很多方面定义了默认值

Gradle cookbook(转)

原文地址 http://www.gradle.org/docs/current/userguide/installation.html 4.1. Prerequisites先决条件 Gradle依赖于JDK,需要已经安装好5.0(包括)以上的版本.虽然Gradle是基于Groovy配置的,但是不需要安装Groovy,它自带了.如果你已经安装了Groovy,没有关系,它会忽略掉的. Gradle会在Path路径寻找JDK,找到哪个版本就用哪个版本.你自己可以用 java -version来检查你的

Android开发:《Gradle Recipes for Android》阅读笔记(翻译)2.5——在项目中共享配置

问题: 取出多个模块下相同的配置 解决方案: 在顶级gradle配置文件里面使用allprojects或者subprojects块 讨论: 当你在android studio中新建android项目时,IDE创建了一个两级的gradle项目,一个配置文件在根目录下,一个在叫app的模块目录下.顶级的build.gradle有几个叫allprojects的块: 这个块是gradle的语法,所以不只是在adroid项目中,在所有基于gradle的项目中都能使用.allprojects属性来源于Gra

[Gradle] 在 Eclipse 下利用 gradle 构建系统

转载自:http://www.ibm.com/developerworks/cn/opensource/os-cn-gradle/ 构建系统时候常常要用到 Ant, Maven 等工具,对于初学者来说,它们还是过于复杂,上手还是需要时间的.本文将向读者介绍一种全新的构建项目的方式 gradle,它简单.上手快,能大大节省项目的时间和成本. 在 eclipse 下利用 gradle 构建系统 基本开发环境 操作系统:本教程使用的为 Windows Vista Enterprise, 如果您的系统是

(转)eclipse下 gradle构建项目

原文:http://www.ibm.com/developerworks/cn/opensource/os-cn-gradle/ 在 eclipse 下利用 gradle 构建系统 基本开发环境 操作系统:本教程使用的为 Windows Vista Enterprise, 如果您的系统是 Linux 的,请选择下载对应版本的其他工具,包括开发工具.Java EE 服务器.Apache Ant.SoapUI. 开发工具:Eclipse IDE for SOA Developers 版本,请到 ht

zz深入理解Android之Gradle

http://blog.csdn.net/innost/article/details/48228651 Gradle是当前非常“劲爆”得构建工具.本篇文章就是专为讲解Gradle而来.介绍Gradle之前,先说点题外话. 一.题外话 说实话,我在大法工作的时候,就见过Gradle.但是当时我一直不知道这是什么东西.而且大法工具组的工程师还将其和Android Studio大法版一起推送,偶一看就更没兴趣了.为什么那个时候如此不待见Gradle呢?因为我此前一直是做ROM开发.在这个层面上,我们

在 Eclipse 下利用 gradle 构建系统

在 eclipse 下利用 gradle 构建系统 基本开发环境 操作系统:本教程使用的为 Windows Vista Enterprise, 如果您的系统是 Linux 的,请选择下载对应版本的其他工具,包括开发工具.Java EE 服务器.Apache Ant.SoapUI. 开发工具:Eclipse IDE for SOA Developers 版本,请到 http://www.eclipse.org/downloads/ 网站下载,当然任何版本的 eclipse 都是可以的. Java