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) {
throw new GradleException("Must specify license and notice file for project ${project.path}")
}
jarTask.into('META-INF') {
jarTask.metaInf {
from(project.licenseFile.parent) {
include project.licenseFile.name
}

View File

@ -18,6 +18,7 @@
*/
package org.elasticsearch.gradle.precommit
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
import org.gradle.api.Project
import org.gradle.api.Task
@ -83,17 +84,14 @@ class PrecommitTasks {
getClass().getResource('/forbidden/es-all-signatures.txt')]
suppressAnnotations = ['**.SuppressForbidden']
}
Task mainForbidden = project.tasks.findByName('forbiddenApisMain')
if (mainForbidden != null) {
mainForbidden.configure {
signaturesURLs += getClass().getResource('/forbidden/es-server-signatures.txt')
}
}
Task testForbidden = project.tasks.findByName('forbiddenApisTest')
if (testForbidden != null) {
testForbidden.configure {
signaturesURLs += getClass().getResource('/forbidden/es-test-signatures.txt')
signaturesURLs += getClass().getResource('/forbidden/http-signatures.txt')
project.tasks.withType(CheckForbiddenApis) {
// we do not use the += operator to add signatures, as conventionMappings of Gradle do not work when it's configured using withType:
if (name.endsWith('Test')) {
signaturesURLs = project.forbiddenApis.signaturesURLs +
[ getClass().getResource('/forbidden/es-test-signatures.txt'), getClass().getResource('/forbidden/http-signatures.txt') ]
} else {
signaturesURLs = project.forbiddenApis.signaturesURLs +
[ getClass().getResource('/forbidden/es-server-signatures.txt') ]
}
}
Task forbiddenApis = project.tasks.findByName('forbiddenApis')
@ -144,21 +142,15 @@ class PrecommitTasks {
]
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) {
dependsOn(copyCheckstyleConf)
project.tasks.withType(Checkstyle) { task ->
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

View File

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