web-dev-qa-db-ja.com

Gradle compileJavaタスクの警告:[オプション] 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] -----------------------------------------------------

なに?

38
mre

詳細はクロスコンパイル のjavacドキュメントを参照してください。ただし、基本的には、ターゲットバージョンに存在しない、または異なる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
})

そうは言っても、Java6のjdk6をベースに構築しているように見えるので、警告を無視しても安全だと思います。 gradleは7ではなくjdk6の下で実行されていますか?

12
Matt

bootstrap bootClasspathオプションを使用してクラスパスを指定できます:

apply plugin: 'Java'

sourceCompatibility = 1.6
targetCompatibility = 1.6

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

プロジェクト内のすべてのコンパイルタスクでbootClasspathオプションを設定するには、TaskContainerでwithType()メソッドを使用して、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

詳細については、 documentation をご覧ください。

13

Rudikの答えは、Gradle 2.0以降で動作するように少し修正する必要があります。「Compile」プロパティを「JavaCompile」に変更する必要があります。参照: Gradle 2.0にアップグレードした後:ルートプロジェクトでプロパティ 'Compile'が見つかりませんでした

元のポスターの問題に遭遇しました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

元の回答を投稿してくれたRudikに再び感謝します。新しい回答を作成する代わりにコメントを追加したかったのですが、評判ポイントが(まだ)ありませんでした。

3
Paul M

ワークスペースレベルでgradle用のJVMを定義するソリューションは理想的ではありません。異なるJVM上の複数のプロジェクト/ビルドの場合、これは使用できません。

Spring Gradleプラグイン(3.3.0)を使用するEclipse Keplerでは、gradleビルドタスク(外部ツール)のJVMを定義できます。

External Tool Configuration | Arguments | Java Homeビルドに使用するJVMを定義できます.

1
OblongZebra