Make JarHell task cacheable (#42551)
This commit is contained in:
parent
7cabe8acc9
commit
2a0c30c100
|
@ -107,14 +107,12 @@ class PrecommitTasks {
|
|||
}
|
||||
|
||||
private static Task configureJarHell(Project project) {
|
||||
Task task = project.tasks.create('jarHell', JarHellTask.class)
|
||||
task.classpath = project.sourceSets.test.runtimeClasspath
|
||||
if (project.plugins.hasPlugin(ShadowPlugin)) {
|
||||
task.classpath += project.configurations.bundle
|
||||
return project.tasks.create('jarHell', JarHellTask) { task ->
|
||||
task.classpath = project.sourceSets.test.runtimeClasspath
|
||||
if (project.plugins.hasPlugin(ShadowPlugin)) {
|
||||
task.classpath += project.configurations.bundle
|
||||
}
|
||||
}
|
||||
task.dependsOn(project.sourceSets.test.classesTaskName)
|
||||
task.javaHome = project.runtimeJavaHome
|
||||
return task
|
||||
}
|
||||
|
||||
private static Task configureThirdPartyAudit(Project project) {
|
||||
|
|
|
@ -21,19 +21,20 @@ package org.elasticsearch.gradle.precommit;
|
|||
|
||||
import org.elasticsearch.gradle.LoggedExec;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.tasks.Classpath;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.CacheableTask;
|
||||
import org.gradle.api.tasks.CompileClasspath;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Runs CheckJarHell on a classpath.
|
||||
*/
|
||||
@CacheableTask
|
||||
public class JarHellTask extends PrecommitTask {
|
||||
|
||||
private FileCollection classpath;
|
||||
|
||||
private Object javaHome;
|
||||
|
||||
public JarHellTask() {
|
||||
setDescription("Runs CheckJarHell on the configured classpath");
|
||||
}
|
||||
|
@ -42,23 +43,15 @@ public class JarHellTask extends PrecommitTask {
|
|||
public void runJarHellCheck() {
|
||||
LoggedExec.javaexec(getProject(), spec -> {
|
||||
spec.classpath(getClasspath());
|
||||
spec.executable(getJavaHome() + "/bin/java");
|
||||
spec.setMain("org.elasticsearch.bootstrap.JarHell");
|
||||
});
|
||||
}
|
||||
|
||||
@Input
|
||||
public Object getJavaHome() {
|
||||
return javaHome;
|
||||
}
|
||||
|
||||
public void setJavaHome(Object javaHome) {
|
||||
this.javaHome = javaHome;
|
||||
}
|
||||
|
||||
@Classpath
|
||||
// We use compile classpath normalization here because class implementation changes are irrelevant for the purposes of jar hell.
|
||||
// We only care about the runtime classpath ABI here.
|
||||
@CompileClasspath
|
||||
public FileCollection getClasspath() {
|
||||
return classpath.filter(file -> file.exists());
|
||||
return classpath.filter(File::exists);
|
||||
}
|
||||
|
||||
public void setClasspath(FileCollection classpath) {
|
||||
|
|
Loading…
Reference in New Issue