Build: Fix Java9 MR build (#29312)

Correctly setup classpath/dependencies and fix checkstyle task that was partly broken because delayed setup of Java9 sourcesets. This also cleans packaging of META-INF. It also prepares forbiddenapis 2.6 upgrade

relates #29292
This commit is contained in:
Uwe Schindler 2018-04-03 19:22:12 +02:00 committed by Ryan Ernst
parent 4db6fc9a08
commit 7c6d5cbf1f
3 changed files with 35 additions and 27 deletions

View File

@ -551,7 +551,7 @@ class BuildPlugin implements Plugin<Project> {
if (project.licenseFile == null || project.noticeFile == null) { if (project.licenseFile == null || project.noticeFile == null) {
throw new GradleException("Must specify license and notice file for project ${project.path}") throw new GradleException("Must specify license and notice file for project ${project.path}")
} }
jarTask.into('META-INF') { jarTask.metaInf {
from(project.licenseFile.parent) { from(project.licenseFile.parent) {
include project.licenseFile.name include project.licenseFile.name
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.elasticsearch.gradle.precommit package org.elasticsearch.gradle.precommit
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
@ -83,17 +84,14 @@ class PrecommitTasks {
getClass().getResource('/forbidden/es-all-signatures.txt')] getClass().getResource('/forbidden/es-all-signatures.txt')]
suppressAnnotations = ['**.SuppressForbidden'] suppressAnnotations = ['**.SuppressForbidden']
} }
Task mainForbidden = project.tasks.findByName('forbiddenApisMain') project.tasks.withType(CheckForbiddenApis) {
if (mainForbidden != null) { // we do not use the += operator to add signatures, as conventionMappings of Gradle do not work when it's configured using withType:
mainForbidden.configure { if (name.endsWith('Test')) {
signaturesURLs += getClass().getResource('/forbidden/es-server-signatures.txt') signaturesURLs = project.forbiddenApis.signaturesURLs +
} [ getClass().getResource('/forbidden/es-test-signatures.txt'), getClass().getResource('/forbidden/http-signatures.txt') ]
} } else {
Task testForbidden = project.tasks.findByName('forbiddenApisTest') signaturesURLs = project.forbiddenApis.signaturesURLs +
if (testForbidden != null) { [ getClass().getResource('/forbidden/es-server-signatures.txt') ]
testForbidden.configure {
signaturesURLs += getClass().getResource('/forbidden/es-test-signatures.txt')
signaturesURLs += getClass().getResource('/forbidden/http-signatures.txt')
} }
} }
Task forbiddenApis = project.tasks.findByName('forbiddenApis') Task forbiddenApis = project.tasks.findByName('forbiddenApis')
@ -144,21 +142,15 @@ class PrecommitTasks {
] ]
toolVersion = 7.5 toolVersion = 7.5
} }
for (String taskName : ['checkstyleMain', 'checkstyleJava9', 'checkstyleTest']) {
Task task = project.tasks.findByName(taskName)
if (task != null) {
project.tasks['check'].dependsOn.remove(task)
checkstyleTask.dependsOn(task)
task.dependsOn(copyCheckstyleConf)
task.inputs.file(checkstyleSuppressions)
task.reports {
html.enabled false
}
}
}
project.tasks.withType(Checkstyle) { project.tasks.withType(Checkstyle) { task ->
dependsOn(copyCheckstyleConf) project.tasks[JavaBasePlugin.CHECK_TASK_NAME].dependsOn.remove(task)
checkstyleTask.dependsOn(task)
task.dependsOn(copyCheckstyleConf)
task.inputs.file(checkstyleSuppressions)
task.reports {
html.enabled false
}
} }
return checkstyleTask return checkstyleTask

View File

@ -45,14 +45,30 @@ if (!isEclipse && !isIdea) {
} }
} }
} }
configurations {
java9Compile.extendsFrom(compile)
}
dependencies {
java9Compile sourceSets.main.output
}
compileJava9Java { compileJava9Java {
sourceCompatibility = 9 sourceCompatibility = 9
targetCompatibility = 9 targetCompatibility = 9
} }
/* Enable this when forbiddenapis was updated to 2.6.
* See: https://github.com/elastic/elasticsearch/issues/29292
forbiddenApisJava9 {
targetCompatibility = 9
}
*/
jar { jar {
into('META-INF/versions/9') { metaInf {
into 'versions/9'
from sourceSets.java9.output from sourceSets.java9.output
} }
manifest.attributes('Multi-Release': 'true') manifest.attributes('Multi-Release': 'true')