|
12 | 12 | import org.elasticsearch.gradle.internal.InternalPlugin;
|
13 | 13 | import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin;
|
14 | 14 | import org.gradle.api.Action;
|
15 |
| -import org.gradle.api.GradleException; |
16 | 15 | import org.gradle.api.Project;
|
17 | 16 | import org.gradle.api.Task;
|
18 | 17 | import org.gradle.api.artifacts.dsl.DependencyHandler;
|
19 | 18 | import org.gradle.api.plugins.quality.Checkstyle;
|
20 | 19 | import org.gradle.api.plugins.quality.CheckstyleExtension;
|
21 | 20 | import org.gradle.api.provider.Provider;
|
| 21 | +import org.gradle.api.tasks.SourceSetContainer; |
22 | 22 | import org.gradle.api.tasks.TaskProvider;
|
23 | 23 |
|
24 | 24 | import java.io.File;
|
25 | 25 | import java.io.IOException;
|
26 | 26 | import java.io.InputStream;
|
27 | 27 | import java.io.UncheckedIOException;
|
28 | 28 | import java.net.JarURLConnection;
|
29 |
| -import java.net.URI; |
30 |
| -import java.net.URISyntaxException; |
31 | 29 | import java.net.URL;
|
32 | 30 | import java.nio.file.Files;
|
33 | 31 | import java.nio.file.StandardCopyOption;
|
@@ -97,14 +95,17 @@ public void execute(Task task) {
|
97 | 95 | t.reports(r -> r.getHtml().getRequired().set(false));
|
98 | 96 | });
|
99 | 97 |
|
100 |
| - return checkstyleTask; |
101 |
| - } |
| 98 | + // Configure checkstyle tasks with an empty classpath to improve build avoidance. |
| 99 | + // It's optional since our rules only rely on source files anyway. |
| 100 | + project.getExtensions() |
| 101 | + .getByType(SourceSetContainer.class) |
| 102 | + .all( |
| 103 | + sourceSet -> project.getTasks() |
| 104 | + .withType(Checkstyle.class) |
| 105 | + .named(sourceSet.getTaskName("checkstyle", null)) |
| 106 | + .configure(t -> t.setClasspath(project.getObjects().fileCollection())) |
| 107 | + ); |
102 | 108 |
|
103 |
| - private static URI getBuildSrcCodeSource() { |
104 |
| - try { |
105 |
| - return CheckstylePrecommitPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI(); |
106 |
| - } catch (URISyntaxException e) { |
107 |
| - throw new GradleException("Error determining build tools JAR location", e); |
108 |
| - } |
| 109 | + return checkstyleTask; |
109 | 110 | }
|
110 | 111 | }
|
0 commit comments