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 ...
随机推荐
- NET通用平台
NET通用平台.通用权限.易扩展.多语言.多平台架构框架 先拿出我半前年前平台的设计初稿,经过半年的努力我已经完成了该设计稿的所有功能.并且理念已经远远超出该设计稿. 下面是一些博友对我贴子的评价: ...
- 分布式Unique ID的生成方法
分布式Unique ID的生成方法 分布式的Unique ID的用途如此广泛,从业务对象Id到日志的TraceId,本文总结了林林总总的各种生成算法. 1. 发号器 我接触的最早的Unique ID, ...
- 从零開始学android<ImageSwitcher图片切换组件.二十六.>
ImageSwitcher组件的主要功能是完毕图片的切换显示,比如用户在进行图片浏览的时候.能够通过button点击一张张的切换显示的图片,并且使用ImageSwitcher组件在每次切换的时候也能够 ...
- cocos2d-x 3.1.1 学习笔记[2]Sprite 精灵
Sprite应该是用到最多的一个类吧.无法想像一个游戏没有精灵将怎样进行愉快的玩耍. Sprite继承于Node 和 TextureProtocol. Sprite是一个2d的图像. Sprite能够 ...
- 浅谈android的am命令
android系统为大家提供了adb工具,在adb的基础上执行adb shell就可以从PC上对手机侧执行shell命令.和pc的linux系统一样,在系统的默认路径syste/bin下面是可执行程序 ...
- vb实现多用户登录
利用vb实现多用户登录,主要是将vb与数据库实现链接,这个问题在作品展中我们的软件“天天迹录”的登录时用到,但是当时自己只是知道有这么个功能,但是那些代码的含义并不明白,在3个月后的我又有机会接触到它 ...
- 初识google多语言通信框架gRPC系列(四)C++中使用gRPC
我的这几篇文章都是使用gRPC的example,不是直接编译example,而是新建一个项目,从添加依赖,编译example代码,执行example.这样做可以为我们创建自己的项目提供借鉴.如果对gR ...
- [置顶] 利用CXF发布webService的小demo
其实webService的发布不仅仅只有xfire,今天,给大家介绍一下用CXF发布一个webService的小demo,CXF也是我做webService用的第一个框架... 先将相关的jar引进来 ...
- 兔子--Fragment与ViewPager要切换滑动效果
效果图: 文件夹结构: 代码分析: MainActivity.java package com.example.myfragment; /** * @author Arthur Lee * @time ...
- SVA(system verilog assertions)基础
1什么是断言: 断言就是在模拟过程中依据我们事先安排好的逻辑是不是发生了,假设发生断言成功.否则断言失败. 2断言的运行分为:预备(preponed)观察(observed)响应(reactive). ...