Gradle sourceCompatibility has no effect to subprojects(转)

时间:2023-01-25 21:41:12

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://*.com/questions/21028438/gradle-sourcecompatibility-has-no-effect-to-subprojects

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

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

    1.构建基本的Java项目 为了使用 Java 插件,添加下面代码到构建文件: build.gradle apply plugin: 'java' 这个就是 定义一个 Java 项目的全部.它会将 J ...

  2. Gradle方式构建Java多项目

    0: 安装IDEA:Linux 上只需下载IDEA的包 并且将路径配置在PATH全局变量中./etc/profile export PATH=$PATH:/opt/Software/IDEA/idea ...

  3. Gradle cookbook(转)

    build.gradle apply plugin:"java" [compileJava,compileTestJava,javadoc]*.options*.encoding ...

  4. 【转载】Gradle学习 第七章:Java快速入门

    转载地址:http://ask.android-studio.org/?/article/22 7.1. The Java plugin(Java插件) As we have seen, Gradle ...

  5. 深入理解Android之Gradle

    深入理解Android之Gradle 格式更加精美的PDF版请到:http://vdisk.weibo.com/s/z68f8l0xTYrZt 下载 Gradle是当前非常"劲爆" ...

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

      转载自:http://www.ibm.com/developerworks/cn/opensource/os-cn-gradle/ 构建系统时候常常要用到 Ant, Maven 等工具,对于初学者 ...

  7. gradle重复依赖终极方案解决办法

    buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build: ...

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

    问题: 取出多个模块下相同的配置 解决方案: 在*gradle配置文件里面使用allprojects或者subprojects块 讨论: 当你在android studio中新建android项目时 ...

  9. Android Studio androidx 包冲突解决方法

    如果包冲突了会包如下这样的错: Android dependency 'androidx.core:core' has different version for the compile (1.0.0 ...

随机推荐

  1. C++11 新特性: unordered_map 与 map 的对比

    unordered_map和map类似,都是存储的key-value的值,可以通过key快速索引到value.不同的是unordered_map不会根据key的大小进行排序, 存储时是根据key的ha ...

  2. info.plist、pch和四大对象(UIApplication、UIApplicationDelegate、UIWindow、UIViewController)

    本文目录 1.程序配置文件info.plist,全局头文件pch 2.应用程序对象UIApplication介绍 3.UIApplicationDelegate介绍,程序启动过程 4.UIWindow ...

  3. Make Rules

    target: components ls TAB rule main:main.o mytool1.o mytool2.o gcc -o main main.o mytool1.o mytool2. ...

  4. Cookie的前后台应用

    1.jquery.cookie.js的基本应用 这个是第三方js插件,可以更方便的设置和使用cookie $.cookie("UserName", "kingtiger& ...

  5. Qt 中程序自动重启

    参照至 dbzhang老师的博文,记录于此....... 要想理解重启,先得看看Qt程序怎么退出! 1.退出 int main(int argc, char** argv) { QApplicatio ...

  6. spring 源码之IOC 类图

    Spring IoC容器是spring框架的核心和基础,IoC容器负责spring Bean的生命周期,是spring框架实现其他扩展功能的基础.容器的继承结构比较复杂,这里画出了spring IoC ...

  7. DirectShow基础编程 最简单transform filter 编写步骤

    目标编写一个transform filter,功能是对图像进行翻转. 一.选择基类 从CBaseFilter派生出三个用于编写transform filter的类,各自是:CTransformFilt ...

  8. 【学习笔记】Hibernate 注解 (Y2-1-9)

    Hibernate注解 1.什么是注解在类上或者方法上打上其他类型的类型元数据 @标志 使用过的注解: @override  方法重写 @Test Junit 单元测试 @Before 单元测试 @A ...

  9. .Net Core 实践 - 如何在控制台应用(.Net Core)使用appsettings.json配置

    新建控制台应用(.Net Core)程序 添加json文件,命名为appsettings.json,设置文件属性 如果较新则复制.添加内容如下 { "MyWords" : &quo ...

  10. Lodop打印设计里的 打印项对齐

    打印设计界面里,有四个对齐的图标:(1)第一个图标是左右对齐方式,该图标下有四种左右对齐方式.(2)第二个图标是上下对齐方式,该图标下有四种上下对齐方式.(3)第三个图标是等宽对齐,该图标下有三种等宽 ...