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: java
, war
, jetty
, gwt
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 war
, jetty
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
Gradle sourceCompatibility has no effect to subprojects(转)的更多相关文章
- Gradle用户指南(3)-构建Java项目
1.构建基本的Java项目 为了使用 Java 插件,添加下面代码到构建文件: build.gradle apply plugin: 'java' 这个就是 定义一个 Java 项目的全部.它会将 J ...
- Gradle方式构建Java多项目
0: 安装IDEA:Linux 上只需下载IDEA的包 并且将路径配置在PATH全局变量中./etc/profile export PATH=$PATH:/opt/Software/IDEA/idea ...
- Gradle cookbook(转)
build.gradle apply plugin:"java" [compileJava,compileTestJava,javadoc]*.options*.encoding ...
- 【转载】Gradle学习 第七章:Java快速入门
转载地址:http://ask.android-studio.org/?/article/22 7.1. The Java plugin(Java插件) As we have seen, Gradle ...
- 深入理解Android之Gradle
深入理解Android之Gradle 格式更加精美的PDF版请到:http://vdisk.weibo.com/s/z68f8l0xTYrZt 下载 Gradle是当前非常"劲爆" ...
- [Gradle] 在 Eclipse 下利用 gradle 构建系统
转载自:http://www.ibm.com/developerworks/cn/opensource/os-cn-gradle/ 构建系统时候常常要用到 Ant, Maven 等工具,对于初学者 ...
- gradle重复依赖终极方案解决办法
buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build: ...
- Android开发:《Gradle Recipes for Android》阅读笔记(翻译)2.5——在项目中共享配置
问题: 取出多个模块下相同的配置 解决方案: 在顶级gradle配置文件里面使用allprojects或者subprojects块 讨论: 当你在android studio中新建android项目时 ...
- Android Studio androidx 包冲突解决方法
如果包冲突了会包如下这样的错: Android dependency 'androidx.core:core' has different version for the compile (1.0.0 ...
随机推荐
- windows phone 7,sliverlight 下载网页的解析,关于wp7 gb2312编码
原文:windows phone 7,sliverlight 下载网页的解析,关于wp7 gb2312编码 关于silverlight和wp7(windows phone 7)是默认不支持gb2312 ...
- visual studio 2013常用快捷键 VS2013快捷键大全
visual studio 2013常用快捷键 VS2013快捷键大全 Visual Studio 2013 是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具 ...
- Linux 安装之U盘引导
说到装系统最简单的方法无非就是找个系统安装光盘来然后就一步一步慢慢的安装.简单是简单但好似大多数人好像都木有Linux的安装光盘. 因此仅仅能用U盘来模拟光盘的功能来装系统咯. 电脑上装有Window ...
- 【ThinkingInC++】61、非成员运算符
非成员运算符 当操作者的左侧是不同的类时.运算符重载不可能是正确的类中. IostreamOperatorOverloading.cpp /** * 书本:[ThinkingInC++] * 功能:非 ...
- 递归算法的数据结构和算法 C++和PHP达到
递归算法:它是一种间接的方法调用本身,直接或. 实施过程:按功能或子程序完成.在函数编写代码或子程序直接或间接拥有被称为.你可以完成递归. (相同类型的问题,子问题到最小问题有已知条件,然后来求解,然 ...
- Java EE (2) -- Java EE 6 Enterprise JavaBeans Developer Certified Expert(1z0-895)
Introduction to Java EE Gain an understanding of the Java Platform, Enterprise Edition (Java EE) Exa ...
- wireshark教程
Wireshark世界上最流行的网络分析工具. 这个强大的工具能够捕捉网络中的数据,并为用户提供关于网络和上层协议的各种信息.与非常多其它网络工具一样.Wireshark也使用pcap network ...
- Effective C++:规定20: 宁pass-by-reference-to-const更换pass-by-value
(一) 假设传递参数当函数被调用pass-by-value,然后函数的参数是基于实际参数的副本最初值,调用,也得到该函数返回的结束值复印件. 请看下面的代码: class Person { publi ...
- 【读书札记】建立第一个Web项目
安装配置好jdk.tomcat,我用的版本号是7.0.54,我放在C:\server\apache-tomcat-7.0.54下, CATALINA_BASE:C:\server\apache-tom ...
- 智能家居项目(3):编译工具makefile
board文件夹中,基本的代码结构分为了src,include两个子文件夹.分别存放源码文件. #CC=arm-linux-gcc CC=gcc CFLAGS=-lpthread INCPATH=-I ...