Skip to content

Commit 6adab84

Browse files
uschindlerrjernst
authored andcommitted
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
1 parent dec3948 commit 6adab84

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

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

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy

+17-25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.elasticsearch.gradle.precommit
2020

21+
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
2122
import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
2223
import org.gradle.api.Project
2324
import org.gradle.api.Task
@@ -83,17 +84,14 @@ class PrecommitTasks {
8384
getClass().getResource('/forbidden/es-all-signatures.txt')]
8485
suppressAnnotations = ['**.SuppressForbidden']
8586
}
86-
Task mainForbidden = project.tasks.findByName('forbiddenApisMain')
87-
if (mainForbidden != null) {
88-
mainForbidden.configure {
89-
signaturesURLs += getClass().getResource('/forbidden/es-server-signatures.txt')
90-
}
91-
}
92-
Task testForbidden = project.tasks.findByName('forbiddenApisTest')
93-
if (testForbidden != null) {
94-
testForbidden.configure {
95-
signaturesURLs += getClass().getResource('/forbidden/es-test-signatures.txt')
96-
signaturesURLs += getClass().getResource('/forbidden/http-signatures.txt')
87+
project.tasks.withType(CheckForbiddenApis) {
88+
// we do not use the += operator to add signatures, as conventionMappings of Gradle do not work when it's configured using withType:
89+
if (name.endsWith('Test')) {
90+
signaturesURLs = project.forbiddenApis.signaturesURLs +
91+
[ getClass().getResource('/forbidden/es-test-signatures.txt'), getClass().getResource('/forbidden/http-signatures.txt') ]
92+
} else {
93+
signaturesURLs = project.forbiddenApis.signaturesURLs +
94+
[ getClass().getResource('/forbidden/es-server-signatures.txt') ]
9795
}
9896
}
9997
Task forbiddenApis = project.tasks.findByName('forbiddenApis')
@@ -144,21 +142,15 @@ class PrecommitTasks {
144142
]
145143
toolVersion = 7.5
146144
}
147-
for (String taskName : ['checkstyleMain', 'checkstyleJava9', 'checkstyleTest']) {
148-
Task task = project.tasks.findByName(taskName)
149-
if (task != null) {
150-
project.tasks['check'].dependsOn.remove(task)
151-
checkstyleTask.dependsOn(task)
152-
task.dependsOn(copyCheckstyleConf)
153-
task.inputs.file(checkstyleSuppressions)
154-
task.reports {
155-
html.enabled false
156-
}
157-
}
158-
}
159145

160-
project.tasks.withType(Checkstyle) {
161-
dependsOn(copyCheckstyleConf)
146+
project.tasks.withType(Checkstyle) { task ->
147+
project.tasks[JavaBasePlugin.CHECK_TASK_NAME].dependsOn.remove(task)
148+
checkstyleTask.dependsOn(task)
149+
task.dependsOn(copyCheckstyleConf)
150+
task.inputs.file(checkstyleSuppressions)
151+
task.reports {
152+
html.enabled false
153+
}
162154
}
163155

164156
return checkstyleTask

server/build.gradle

+17-1
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,30 @@ if (!isEclipse && !isIdea) {
4545
}
4646
}
4747
}
48+
49+
configurations {
50+
java9Compile.extendsFrom(compile)
51+
}
52+
53+
dependencies {
54+
java9Compile sourceSets.main.output
55+
}
4856

4957
compileJava9Java {
5058
sourceCompatibility = 9
5159
targetCompatibility = 9
5260
}
61+
62+
/* Enable this when forbiddenapis was updated to 2.6.
63+
* See: https://github.com/elastic/elasticsearch/issues/29292
64+
forbiddenApisJava9 {
65+
targetCompatibility = 9
66+
}
67+
*/
5368

5469
jar {
55-
into('META-INF/versions/9') {
70+
metaInf {
71+
into 'versions/9'
5672
from sourceSets.java9.output
5773
}
5874
manifest.attributes('Multi-Release': 'true')

0 commit comments

Comments
 (0)