|
23 | 23 | import org.gradle.api.Task;
|
24 | 24 | import org.gradle.api.artifacts.Configuration;
|
25 | 25 | import org.gradle.api.file.FileCollection;
|
| 26 | +import org.gradle.api.plugins.JavaPlugin; |
26 | 27 | import org.gradle.api.tasks.SourceSet;
|
27 | 28 | import org.gradle.api.tasks.SourceSetContainer;
|
28 | 29 | import org.gradle.api.tasks.testing.Test;
|
@@ -194,17 +195,17 @@ public void execute(Task t) {
|
194 | 195 | * compiled class output and dependency jars. This better emulates the runtime environment of consumers.
|
195 | 196 | */
|
196 | 197 | project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> {
|
197 |
| - // Remove output class files and any other dependencies from the test classpath, since the shadow JAR includes these |
198 |
| - FileCollection mainRuntime = project.getExtensions() |
199 |
| - .getByType(SourceSetContainer.class) |
200 |
| - .getByName(SourceSet.MAIN_SOURCE_SET_NAME) |
201 |
| - .getRuntimeClasspath(); |
202 |
| - // Add any "shadow" dependencies. These are dependencies that are *not* bundled into the shadow JAR |
203 |
| - Configuration shadowConfig = project.getConfigurations().getByName(ShadowBasePlugin.getCONFIGURATION_NAME()); |
204 |
| - // Add the shadow JAR artifact itself |
205 |
| - FileCollection shadowJar = project.files(project.getTasks().named("shadowJar")); |
206 |
| - |
207 |
| - test.setClasspath(test.getClasspath().minus(mainRuntime).plus(shadowConfig).plus(shadowJar)); |
| 198 | + if (test.getName().equals(JavaPlugin.TEST_TASK_NAME)) { |
| 199 | + // Remove output class files and any other dependencies from the test classpath, since the shadow JAR includes these |
| 200 | + SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); |
| 201 | + FileCollection mainRuntime = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); |
| 202 | + // Add any "shadow" dependencies. These are dependencies that are *not* bundled into the shadow JAR |
| 203 | + Configuration shadowConfig = project.getConfigurations().getByName(ShadowBasePlugin.getCONFIGURATION_NAME()); |
| 204 | + // Add the shadow JAR artifact itself |
| 205 | + FileCollection shadowJar = project.files(project.getTasks().named("shadowJar")); |
| 206 | + FileCollection testRuntime = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getRuntimeClasspath(); |
| 207 | + test.setClasspath(testRuntime.minus(mainRuntime).plus(shadowConfig).plus(shadowJar)); |
| 208 | + } |
208 | 209 | });
|
209 | 210 | });
|
210 | 211 | }
|
|
0 commit comments