Gradle compileJava task warning: [options] bootstrap class path not set in conjunction with -source 1.6

匿名 (未验证) 提交于 2019-12-03 01:08:02

问题:

Below is the content of the build.gradle file:

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  } 

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?

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!


UPDATE

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

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

What do?

回答1:

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.

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

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?



回答2:

You can bootstrap class path using bootClasspath option:

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

To set the bootClasspath option on all compile tasks in the project you can use the withType() method on the TaskContainer to find all tasks of type Compile:

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

gradle.properties:

JDK6_HOME=C:/JAVA/jdk6 

See documentation for details.



回答3:

Rudik's answer needs a small modification to work with Gradle 2.0 and above: The "Compile" property must be changed to "JavaCompile." See: After upgrading to Gradle 2.0: Could not find property 'Compile' on root project

I ran into the original poster's problem on Android Studio 2.2.2 (JDK8) compiling for Google App Engine (Java 7). Here is Rudik's answer accordingly modified to fix this scenario:

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

And again in gradle.properties, add whatever your path is to the JDK, e.g. for Mac

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

Thanks again to Rudik for posting the original answer. I wanted to add a comment instead of creating a new answer, but did not have enough reputation points (yet).



回答4:

The solution to define the JVM for gradle at workspace level is not ideal. In the case of multiple projects/builds on different JVMs, this cannot be used.

In Eclipse Kepler with Spring Gradle plugin (3.3.0) it is possible to define the JVM for your gradle build task (External tool).

At External Tool Configuration | Arguments | Java Home you can define which JVM should be used for the build.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!