Skip to content

Commit bf1bfc4

Browse files
committed
Fix optional dependencies having compile scope in poms
Closes gh-729
1 parent c0477a6 commit bf1bfc4

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

buildSrc/src/main/java/org/springframework/restdocs/build/optional/OptionalDependenciesPlugin.java

+25-9
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
import org.gradle.api.Plugin;
2020
import org.gradle.api.Project;
2121
import org.gradle.api.artifacts.Configuration;
22-
import org.gradle.api.attributes.Bundling;
23-
import org.gradle.api.attributes.LibraryElements;
2422
import org.gradle.api.attributes.Usage;
2523
import org.gradle.api.plugins.JavaPlugin;
2624
import org.gradle.api.plugins.JavaPluginConvention;
25+
import org.gradle.api.publish.PublishingExtension;
26+
import org.gradle.api.publish.maven.MavenPublication;
27+
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
2728
import org.gradle.api.tasks.SourceSetContainer;
2829
import org.gradle.api.tasks.javadoc.Javadoc;
30+
import org.gradle.plugins.ide.eclipse.EclipsePlugin;
31+
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
2932

3033
/**
3134
* A {@code Plugin} that adds support for Maven-style optional dependencies. Creates a new
@@ -45,13 +48,26 @@ public class OptionalDependenciesPlugin implements Plugin<Project> {
4548
@Override
4649
public void apply(Project project) {
4750
Configuration optional = project.getConfigurations().create(OPTIONAL_CONFIGURATION_NAME);
48-
project.getConfigurations().getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME).extendsFrom(optional);
49-
project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(optional);
50-
project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(optional);
51-
project.getConfigurations().getByName(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(optional);
52-
project.getConfigurations().getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(optional);
53-
project.getConfigurations().getByName(JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME).extendsFrom(optional);
54-
project.getConfigurations().getByName(JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME).extendsFrom(optional);
51+
project.getConfigurations().all((configuration) -> {
52+
if (configuration.getName().startsWith("testRuntimeClasspath_")) {
53+
configuration.extendsFrom(optional);
54+
}
55+
});
56+
optional.attributes((attributes) -> attributes.attribute(Usage.USAGE_ATTRIBUTE,
57+
project.getObjects().named(Usage.class, Usage.JAVA_RUNTIME)));
58+
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
59+
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
60+
.getSourceSets();
61+
sourceSets.all((sourceSet) -> {
62+
sourceSet.setCompileClasspath(sourceSet.getCompileClasspath().plus(optional));
63+
sourceSet.setRuntimeClasspath(sourceSet.getRuntimeClasspath().plus(optional));
64+
});
65+
project.getTasks().withType(Javadoc.class)
66+
.all((javadoc) -> javadoc.setClasspath(javadoc.getClasspath().plus(optional)));
67+
});
68+
project.getPlugins().withType(EclipsePlugin.class,
69+
(eclipsePlugin) -> project.getExtensions().getByType(EclipseModel.class)
70+
.classpath((classpath) -> classpath.getPlusConfigurations().add(optional)));
5571
}
5672

5773
}

spring-restdocs-asciidoctor/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ dependencies {
1818
merge project(":spring-restdocs-asciidoctor-1.6")
1919
merge project(":spring-restdocs-asciidoctor-2.x")
2020

21+
testImplementation("junit:junit")
2122
testImplementation("org.apache.pdfbox:pdfbox")
2223
testImplementation("org.asciidoctor:asciidoctorj:1.5.8.1")
2324
testImplementation("org.assertj:assertj-core")
24-
testImplementation("junit:junit")
2525
testImplementation("org.springframework:spring-core")
2626

2727
testRuntimeOnly("org.asciidoctor:asciidoctorj-pdf")

spring-restdocs-core/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies {
4343
jmustache(platform(project(":spring-restdocs-platform")))
4444
jmustache("com.samskivert:jmustache@jar")
4545

46+
optional(platform(project(":spring-restdocs-platform")))
4647
optional("commons-codec:commons-codec")
4748
optional("javax.validation:validation-api")
4849
optional("junit:junit")

spring-restdocs-mockmvc/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
internal(platform(project(":spring-restdocs-platform")))
1818

1919
testImplementation(project(path: ":spring-restdocs-core", configuration: "testArtifacts"))
20+
testImplementation("junit:junit")
2021
testImplementation("org.assertj:assertj-core")
2122
testImplementation("org.hamcrest:hamcrest-library")
2223
testImplementation("org.mockito:mockito-core")

spring-restdocs-restassured/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies {
1616

1717
testImplementation(project(path: ":spring-restdocs-core", configuration: "testArtifacts"))
1818
testImplementation("com.fasterxml.jackson.core:jackson-databind")
19+
testImplementation("junit:junit")
1920
testImplementation("org.apache.tomcat.embed:tomcat-embed-core:8.5.13")
2021
testImplementation("org.assertj:assertj-core")
2122
testImplementation("org.hamcrest:hamcrest-library")

spring-restdocs-webtestclient/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
internal(platform(project(":spring-restdocs-platform")))
1515

1616
testImplementation(project(path: ":spring-restdocs-core", configuration: "testArtifacts"))
17+
testImplementation("junit:junit")
1718
testImplementation("org.assertj:assertj-core")
1819
testImplementation("org.hamcrest:hamcrest-library")
1920
testImplementation("org.mockito:mockito-core")

0 commit comments

Comments
 (0)