Подтвердить что ты не робот

Gradle предупреждение задачи compileJava: [options] путь к bootstrap, не установленный вместе с -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] -----------------------------------------------------

Хотя он утверждает, что сборка прошла успешно, предупреждение вызывает у меня немного беспокойство по поводу осложнений во время выполнения. Как разрешить это предупреждение?

Кроме того, я использую Eclipse Indigo. И у меня есть компилятор Java и путь сборки моего проекта к jdk1.6.0_35.

Если кому-то нужна дополнительная информация, пожалуйста, дайте мне знать!


UPDATE

Я перешел на Window > Preferences > Gradle, и я установил "Java Home" в "Workspace JRE" jdk1.6.0_35,

enter image description here

И теперь я получаю следующий вывод, когда запускаю задачу 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] -----------------------------------------------------

Что делать?

4b9b3361

Ответ 1

Смотрите javac docs на кросс-компиляцию для деталей, но в основном это означает, что вы можете скомпилировать классы jdk, которые не существуют, или были разными, в вашей целевой версии. Например, возможно, вы используете java.util.Deque, но нацеливаете на jdk5.

Я не верю, что gradle имеет встроенную поддержку для настройки этого. Я обнаружил, что вам нужно вручную перевернуть задачу компиляции. Например

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?

Ответ 2

Вы можете загружать путь класса с помощью параметра bootClasspath:

apply plugin: 'java'

sourceCompatibility = 1.6
targetCompatibility = 1.6

compileJava.options.bootClasspath = "$JDK6_HOME/jre/lib/rt.jar"

Чтобы установить параметр bootClasspath для всех задач компиляции в проекте, вы можете использовать метод toType() в TaskContainer для поиска всех задач типа Compile:

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

Подробнее см. .

Ответ 3

Ответ Rudik требует небольшой модификации для работы с Gradle 2.0 и выше: свойство "Скомпилировать" должно быть изменено на "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 добавьте все, что ваш путь к JDK, например. для Mac

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

Еще раз спасибо Рудику за отправку оригинального ответа. Я хотел добавить комментарий вместо создания нового ответа, но не имел достаточных точек репутации (пока).

Ответ 4

Решение для определения JVM для gradle на уровне рабочей области не является идеальным. В случае нескольких проектов/сборок на разных JVM это нельзя использовать.

В Eclipse Kepler с плагином Spring gradle (3.3.0) можно определить JVM для задачи сборки gradle (внешний инструмент).

В Конфигурация внешнего инструмента | Аргументы | Java Home вы можете определить, какую JVM следует использовать для сборки.