Voici le contenu du fichier 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
}
Et ci-dessous est le résultat de l'exécution de la tâche 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] -----------------------------------------------------
Bien qu'il affirme que la construction a réussi, l'avertissement m'inquiète un peu des complications d'exécution. Comment résoudre cet avertissement?
De plus, j'utilise Eclipse Indigo. Et j'ai le compilateur Java et le chemin de construction de mon projet sur jdk1.6.0_35.
Si quelqu'un a besoin de plus d'informations, faites-le moi savoir!
MISE À JOUR
J'ai navigué vers Window > Preferences > Gradle et je mets "Java Home" sur le "Workspace JRE" jdk1.6.0_35,
Et maintenant, j'obtiens la sortie suivante lorsque j'exécute la tâche 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] -----------------------------------------------------
Qu'est-ce que?
Voir les documents javac sur compilation croisée pour plus de détails mais en gros cela signifie que vous pouvez compiler avec des classes jdk qui n'existent pas ou étaient différentes sur votre version cible. Par exemple, vous utilisez peut-être Java.util.Deque
mais ciblent jdk5.
Je ne crois pas que Gradle ait intégré le support pour la configuration de cela. J'ai constaté que vous devez modifier manuellement la tâche de compilation. Par exemple
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
})
Cela dit, vous semblez construire sur jdk6 pour Java6, donc je pense que vous pouvez ignorer l'avertissement en toute sécurité. Êtes-vous sûr que Gradle fonctionne sous jdk6 et non 7?
Vous pouvez bootstrap chemin de classe en utilisant l'option bootClasspath:
apply plugin: 'Java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
compileJava.options.bootClasspath = "$JDK6_HOME/jre/lib/rt.jar"
Pour définir l'option bootClasspath sur toutes les tâches de compilation du projet, vous pouvez utiliser la méthode withType () du TaskContainer pour rechercher toutes les tâches de 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
Voir documentation pour plus de détails.
La réponse de Rudik a besoin d'une petite modification pour fonctionner avec Gradle 2.0 et supérieur: la propriété "Compile" doit être changée en "JavaCompile". Voir: Après la mise à niveau vers Gradle 2.0: Impossible de trouver la propriété 'Compiler' sur le projet racine
J'ai rencontré le problème de l'affiche originale sur Android Studio 2.2.2 (JDK8) en cours de compilation pour Google App Engine (Java 7). Voici la réponse de Rudik modifiée en conséquence pour corriger ce scénario:
apply plugin: 'Java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
tasks.withType(JavaCompile) {
options.bootClasspath = "$JDK7_HOME/jre/lib/rt.jar"
}
Et encore une fois dans gradle.properties, ajoutez quel que soit votre chemin d'accès au JDK, par exemple pour Mac
JDK7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home
Merci encore à Rudik d'avoir posté la réponse originale. Je voulais ajouter un commentaire au lieu de créer une nouvelle réponse, mais je n'avais pas encore assez de points de réputation.
La solution pour définir la JVM pour gradle au niveau de l'espace de travail n'est pas idéale. Dans le cas de plusieurs projets/builds sur différentes machines virtuelles Java, cela ne peut pas être utilisé.
Dans Eclipse Kepler avec le plugin Spring Gradle (3.3.0), il est possible de définir la machine virtuelle Java pour votre tâche de construction Gradle (outil externe).
À ( Configuration de l'outil externe | Arguments | Accueil Java vous pouvez définir quelle machine virtuelle Java doit être utilisée pour la construction.