Skip to content

Commit 5ca06a5

Browse files
authored
Make JarHell task cacheable (#42551)
1 parent 1ed7b61 commit 5ca06a5

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,12 @@ class PrecommitTasks {
107107
}
108108

109109
private static Task configureJarHell(Project project) {
110-
Task task = project.tasks.create('jarHell', JarHellTask.class)
111-
task.classpath = project.sourceSets.test.runtimeClasspath
112-
if (project.plugins.hasPlugin(ShadowPlugin)) {
113-
task.classpath += project.configurations.bundle
110+
return project.tasks.create('jarHell', JarHellTask) { task ->
111+
task.classpath = project.sourceSets.test.runtimeClasspath
112+
if (project.plugins.hasPlugin(ShadowPlugin)) {
113+
task.classpath += project.configurations.bundle
114+
}
114115
}
115-
task.dependsOn(project.sourceSets.test.classesTaskName)
116-
task.javaHome = project.runtimeJavaHome
117-
return task
118116
}
119117

120118
private static Task configureThirdPartyAudit(Project project) {

buildSrc/src/main/java/org/elasticsearch/gradle/precommit/JarHellTask.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@
2121

2222
import org.elasticsearch.gradle.LoggedExec;
2323
import org.gradle.api.file.FileCollection;
24-
import org.gradle.api.tasks.Classpath;
25-
import org.gradle.api.tasks.Input;
24+
import org.gradle.api.tasks.CacheableTask;
25+
import org.gradle.api.tasks.CompileClasspath;
2626
import org.gradle.api.tasks.TaskAction;
2727

28+
import java.io.File;
29+
2830
/**
2931
* Runs CheckJarHell on a classpath.
3032
*/
33+
@CacheableTask
3134
public class JarHellTask extends PrecommitTask {
3235

3336
private FileCollection classpath;
3437

35-
private Object javaHome;
36-
3738
public JarHellTask() {
3839
setDescription("Runs CheckJarHell on the configured classpath");
3940
}
@@ -42,23 +43,15 @@ public JarHellTask() {
4243
public void runJarHellCheck() {
4344
LoggedExec.javaexec(getProject(), spec -> {
4445
spec.classpath(getClasspath());
45-
spec.executable(getJavaHome() + "/bin/java");
4646
spec.setMain("org.elasticsearch.bootstrap.JarHell");
4747
});
4848
}
4949

50-
@Input
51-
public Object getJavaHome() {
52-
return javaHome;
53-
}
54-
55-
public void setJavaHome(Object javaHome) {
56-
this.javaHome = javaHome;
57-
}
58-
59-
@Classpath
50+
// We use compile classpath normalization here because class implementation changes are irrelevant for the purposes of jar hell.
51+
// We only care about the runtime classpath ABI here.
52+
@CompileClasspath
6053
public FileCollection getClasspath() {
61-
return classpath.filter(file -> file.exists());
54+
return classpath.filter(File::exists);
6255
}
6356

6457
public void setClasspath(FileCollection classpath) {

0 commit comments

Comments
 (0)