以下是 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。
如果有人需要更多信息,请告诉我们!
更新
我导航到 Window > 偏好设置> Gradle 并将“Java Home”设置为“Workspace 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] -----------------------------------------------------
做什么?
答案 0 :(得分:13)
您可以使用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。
答案 1 :(得分:12)
请参阅cross compilation for details上的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是在jdk6下运行而不是7吗?
答案 2 :(得分:3)
Rudik的答案需要进行一些小修改才能使用Gradle 2.0及更高版本:“编译”属性必须更改为“JavaCompile”。请参阅:After upgrading to Gradle 2.0: Could not find property 'Compile' on root project
我在Android App 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 :(得分:1)
在工作区级别定义用于gradle的JVM的解决方案并不理想。对于不同JVM上的多个项目/构建,不能使用它。
在带有Spring Gradle插件的Eclipse Kepler(3.3.0)中,可以为您的gradle构建任务(外部工具)定义JVM。
外部工具配置 | 参数 | Java Home 您可以定义哪个JVM应该用于构建。