本文介绍了Gradle compileJava 任务警告:[options] 引导类路径未与 -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 任务的结果:

And below is the result of running the Gradle jar task:

[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] -----------------------------------------------------

虽然它声称构建成功,但警告让我有点担心运行时并发症.如何解决此警告?

Although it claims that the build was successful, the warning has me a little worried about run-time complications. How do I resolve this warning?

另外,我正在使用 Eclipse Indigo.我将项目的 Java 编译器和构建路径设置为 jdk1.6.0_35.

Also, I'm using Eclipse Indigo. And I have the Java compiler and build path of my project set to jdk1.6.0_35.

如果有人需要更多信息,请告诉我!

If anyone needs more information, please let me know!

更新

我导航到 > > 并将Java Home"设置为Workspace JRE"jdk1.6.0_35,

I navigated to > > and I set "Java Home" to the "Workspace JRE" jdk1.6.0_35,

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

And now I get the following output when I run the Gradle jar task,

[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts]      :jar
[sts] -----------------------------------------------------
1.6
1.6
1.6
1.6
:compileJavawarning: javalangEnum.class(javalang: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: javalangComparable.class(javalang: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: javalangObject.class(javalang: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: javaioSerializable.class(javaio: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: javalangString.class(javalang: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: javaioInputStream.class(javaio: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: javasecurityKeyStore.class(javasecurity: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: javaxcryptoCipher.class(javaxcrypto: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: javaxcryptospecSecretKeySpec.class(javaxcryptospec: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: javaxxmlindDatatypeConverter.class(javaxxmlind: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: javalangCloneNotSupportedException.class(javalang: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: javalangClass.class(javalang: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: javalangClassLoader.class(javalang: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: javasecurityKeyStore$LoadStoreParameter.class(javasecurity: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: javaioCloseable.class(javaio: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: javalangAutoCloseable.class(javalang: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: javalangException.class(javalang: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: javalangThrowable.class(javalang: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: javasecuritycertCertificate.class(javasecuritycert: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: javasecurityKey.class(javasecurity: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: javasecurityspecKeySpec.class(javasecurityspec: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: javaxcryptoSecretKey.class(javaxcrypto: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: javalangError.class(javalang: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: javasecurityKeyStoreException.class(javasecurity: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: javasecurityGeneralSecurityException.class(javasecurity: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: javalangRuntimeException.class(javalang: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: javaioIOException.class(javaio: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: javasecurityNoSuchAlgorithmException.class(javasecurity: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: javasecuritycertCertificateException.class(javasecuritycert: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: javaxcryptoNoSuchPaddingException.class(javaxcrypto: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: javasecurityInvalidKeyException.class(javasecurity: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: javasecurityKeyException.class(javasecurity: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
ioByteBuffer.class(java
io: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: javaxcryptoIllegalBlockSizeException.class(javaxcrypto: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: javaxcryptoBadPaddingException.class(javaxcrypto: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: javalangStringBuilder.class(javalang: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: javalangAbstractStringBuilder.class(javalang: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: javalangCharSequence.class(javalang: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: javalangStringBuffer.class(javalang: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] -----------------------------------------------------

做什么?

推荐答案

查看 交叉编译了解详情 但基本上这意味着您可以针对目标版本上不存在或不同的 jdk 类进行编译.例如,也许您使用 java.util.Deque 但目标是 jdk5.

See the javac docs on cross compilation for details but basically it means you can compile against jdk classes that don't exist, or were different, on your target version. For example perhaps you use java.util.Deque but are targeting jdk5.

我不相信 gradle 已内置支持设置此项.我发现您需要手动调整编译任务.例如

I don't believe gradle has built in support for setting this. I have found that you need to twiddle the compile task manually. For example

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
})

说了这么多,您似乎是在 jdk6 上为 java6 构建的,所以我认为您可以放心地忽略该警告.你确定 gradle 是在 jdk6 而不是 7 下运行的吗?

Having said all that, you appear to be building on jdk6 for java6 so I would think you can safely ignore the warning. Are you sure gradle is running under jdk6 and not 7?

这篇关于Gradle compileJava 任务警告:[options] 引导类路径未与 -source 1.6 一起设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 21:00