Gradle compileJava任务警告: bootstrap类path没有与-source 1.6一起设置

以下是build.gradle文件的内容:

apply plugin: 'java' archivesBaseName = 'foo-bar' version = '1.0' sourceCompatibility = JavaVersion.VERSION_1_6 targetCompatibility = JavaVersion.VERSION_1_6 sourceSets.main.resources.exclude 'foo.jks' compileJava{ println project.sourceCompatibility println project.targetCompatibility println sourceCompatibility println targetCompatibility } 

下面是运行Gradle jar任务的结果:

 [sts] ----------------------------------------------------- [sts] Starting Gradle build for the following tasks: [sts] :jar [sts] ----------------------------------------------------- 1.6 1.6 1.6 1.6 :compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.6 1 warning :processResources UP-TO-DATE :classes :jar BUILD SUCCESSFUL Total time: 1 mins 3.072 secs [sts] ----------------------------------------------------- [sts] Build finished succesfully! [sts] Time taken: 1 min, 3 sec [sts] ----------------------------------------------------- 

尽pipe它声称构build成功,但这个警告让我有点担心运行时间的复杂性。 我如何解决这个警告?

另外,我正在使用Eclipse Indigo。 我有我的项目的Java编译器和生成path设置为jdk1.6.0_35。

如果有人需要更多的信息,请让我知道!


UPDATE

我导航到窗口 > 首选项 > Gradle ,我把“Java Home”设置为“工作区JRE”jdk1.6.0_35,

在这里输入图像说明

现在我运行Gradle jar任务时得到以下输出,

 [sts] ----------------------------------------------------- [sts] Starting Gradle build for the following tasks: [sts] :jar [sts] ----------------------------------------------------- 1.6 1.6 1.6 1.6 :compileJavawarning: java\lang\Enum.class(java\lang:Enum.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\Comparable.class(java\lang:Comparable.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\Object.class(java\lang:Object.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\io\Serializable.class(java\io:Serializable.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\String.class(java\lang:String.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\io\InputStream.class(java\io:InputStream.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\KeyStore.class(java\security:KeyStore.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: javax\crypto\Cipher.class(javax\crypto:Cipher.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: javax\crypto\spec\SecretKeySpec.class(javax\crypto\spec:SecretKeySpec.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: javax\xml\bind\DatatypeConverter.class(javax\xml\bind:DatatypeConverter.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\CloneNotSupportedException.class(java\lang:CloneNotSupportedException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\Class.class(java\lang:Class.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\ClassLoader.class(java\lang:ClassLoader.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\KeyStore$LoadStoreParameter.class(java\security:KeyStore$LoadStoreParameter.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\io\Closeable.class(java\io:Closeable.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\AutoCloseable.class(java\lang:AutoCloseable.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\Exception.class(java\lang:Exception.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\Throwable.class(java\lang:Throwable.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\cert\Certificate.class(java\security\cert:Certificate.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\Key.class(java\security:Key.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\spec\KeySpec.class(java\security\spec:KeySpec.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: javax\crypto\SecretKey.class(javax\crypto:SecretKey.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\Error.class(java\lang:Error.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\KeyStoreException.class(java\security:KeyStoreException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\GeneralSecurityException.class(java\security:GeneralSecurityException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\RuntimeException.class(java\lang:RuntimeException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\io\IOException.class(java\io:IOException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\NoSuchAlgorithmException.class(java\security:NoSuchAlgorithmException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\cert\CertificateException.class(java\security\cert:CertificateException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: javax\crypto\NoSuchPaddingException.class(javax\crypto:NoSuchPaddingException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\InvalidKeyException.class(java\security:InvalidKeyException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\security\KeyException.class(java\security:KeyException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\nio\ByteBuffer.class(java\nio:ByteBuffer.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: javax\crypto\IllegalBlockSizeException.class(javax\crypto:IllegalBlockSizeException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: javax\crypto\BadPaddingException.class(javax\crypto:BadPaddingException.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\StringBuilder.class(java\lang:StringBuilder.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\AbstractStringBuilder.class(java\lang:AbstractStringBuilder.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\CharSequence.class(java\lang:CharSequence.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. warning: java\lang\StringBuffer.class(java\lang:StringBuffer.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded. 39 warnings :processResources UP-TO-DATE :classes :jar BUILD SUCCESSFUL Total time: 1.96 secs [sts] ----------------------------------------------------- [sts] Build finished succesfully! [sts] Time taken: 0 min, 1 sec [sts] ----------------------------------------------------- 

做什么?

有关详细信息,请参阅交叉编译的javac文档,但基本上,这意味着您可以针对目标版本上不存在或不同的jdk类进行编译。 例如也许你使用java.util.Deque但是定位jdk5。

我不相信Gradle已经build立了对这个设置的支持。 我发现你需要手动编译任务。 例如

 def bootClasspathStr = "${yourJavaVersionXInstallationPath}/jre/lib/rt.jar" project.tasks.withType(AbstractCompile, { AbstractCompile ac -> ac.options.bootClasspath = bootClasspathStr // options is always there but not defined on AbstractCompile so going to hit it anyway }) 

说了这么多,你似乎是build立在java6的jdk6,所以我认为你可以放心地忽略这个警告。 你确定gradle运行在jdk6而不是7吗?

您可以使用bootClasspath选项来引导类path:

 apply plugin: 'java' sourceCompatibility = 1.6 targetCompatibility = 1.6 compileJava.options.bootClasspath = "$JDK6_HOME/jre/lib/rt.jar" 

要在项目中的所有编译任务上设置bootClasspath选项,您可以使用TaskContainer上的withType()方法来查找Compiletypes的所有任务:

 apply plugin: 'java' sourceCompatibility = 1.6 targetCompatibility = 1.6 tasks.withType(Compile) { options.bootClasspath = "$JDK6_HOME/jre/lib/rt.jar" } 

gradle.properties:

 JDK6_HOME=C:/JAVA/jdk6 

详细信息请参阅文档 。

Rudik的答案需要修改一下Gradle 2.0以上的版本:“Compile”属性必须改为“JavaCompile”。 请参阅: 升级到Gradle 2.0之后:在根项目上找不到属性“编译”

我在Android Studio 2.2.2(JDK8)编译Google App Engine(Java 7)时遇到了原始海报的问题。 这里Rudik的答案相应地修改以解决这种情况:

 apply plugin: 'java' sourceCompatibility = 1.7 targetCompatibility = 1.7 tasks.withType(JavaCompile) { options.bootClasspath = "$JDK7_HOME/jre/lib/rt.jar" } 

再次在gradle.properties中,添加你的path到JDK,例如Mac

 JDK7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home 

再次感谢Rudik公布原始答案。 我想添加评论,而不是创build一个新的答案,但没有足够的声望点(还)。

在工作区级别定义用于gradle的JVM的解决scheme并不理想。 在多个项目/构build在不同的JVM上的情况下,这不能被使用。

在Eclipse Kepler中使用Spring Gradle插件(3.3.0),可以为Gradle构build任务定义JVM(外部工具)。

外部工具configuration | 参数 | Java Home中,您可以定义应该使用哪个JVM进行构build。