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-08-07 17:53:29

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

Gradle cookbook(转)

build.gradle apply plugin:"java" [compileJava,compileTestJava,javadoc]*.options*.encoding = 'UTF-8' sourceCompatibility = '1.6' targetCompatibility = '1.6' buildDir = "target" version = '1.0' sourceSets{ main{ java{ srcDirs 'src' } } }

Gradle学习之Eclipse构建Gradle工程

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

深入理解Android之Gradle

深入理解Android之Gradle 格式更加精美的PDF版请到http://vdisk.weibo.com/s/z68f8l0xTYrZt 下载 Gradle是当前非常"劲爆"得构建工具.本篇文章就是专为讲解Gradle而来.介绍Gradle之前先说点题外话. 一.题外话 说实话我在大法工作的时候就见过Gradle.但是当时我一直不知道这是什么东西.而且大法工具组的工程师还将其和Android Studio大法版一起推送偶一看就更没兴趣了.为什么那个时候如此不待见Gradle呢因为我

Android Studio使用教程(四):Gradle基础_Android

其实很早之前也写了一篇Gradle的基础博客,但是时间很久了,现在Gradle已经更新了很多,所以暂且结合Stduio 1.0正式版与最新的Gradle语法来详细讲解下,小伙伴们直接跟我一步步来学习吧. 什么是Gradle? Gradle是一种依赖管理工具,基于Groovy语言,面向Java应用为主,它抛弃了基于XML的各种繁琐配置,取而代之的是一种基于Groovy的内部领域特定(DSL)语言. 安装Gradle 在Android Studio系列教程一–下载与安装中新建项目成功后会下载Grad

Gradle构建多模块项目

废话不多说,直接进入主题. 1. 创建项目 首先创建项目,名称为 test: mkdir test && cd test gradle init 这时候的项目结构如下: test tree . ├── build.gradle ├── gradle │   └── wrapper │   ├── gradle-wrapper.jar │   └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.grad

Gradle构建多模块项目(转)

  废话不多说,直接进入主题. 1. 创建项目 首先创建项目,名称为 test: mkdir test && cd test gradle init 这时候的项目结构如下: test tree . ├── build.gradle ├── gradle │   └── wrapper │   ├── gradle-wrapper.jar │   └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gr

Spring Boot 项目构建 之 使用 Gradle 构建 Java 项目(Building Java Projects with Gradle)

Table of contents What you'll build What you'll need How to complete this guide Set up the project Install Gradle Find out what Gradle can do Build Java code Declare dependencies Build your project with Gradle Wrapper Summary Tags gradle Concepts and

android Gradle的几个基本概念

什么是Gradle? Gradle是一种依赖管理工具,基于Groovy语言,面向Java应用为主,它抛弃了基于XML的各种繁琐配置,取而代之的是一种基于Groovy的内部领域特定(DSL)语言. Gradle 基本概念 接下来我们以9GAG为例 9GAG/app/build.gradle 这个文件是app文件夹下这个Module的gradle配置文件,也可以算是整个项目最主要的gradle配置文件,我们来看下这个文件的内容: // 声明是Android程序 apply plugin: 'com.

gradle中使用cobertura做代码覆盖(转)

gradle很好用,但是默认是没有代码覆盖功能的,只好自己写.曾经在网上找到过别人的一段脚本,虽然也能用,但是有一些不爽的地方,一个原因是它不支持对层级工程中全部代码的覆盖,另一个原因是它用替换build/classes/main里面的class文件,再依赖gradle的单元方式来实现的.我自己写了一个代码覆盖的脚本,可以避免这两个问题,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28