Model that a Maven dependency is optional

Closes gh-913
This commit is contained in:
Stephane Nicoll
2019-05-31 09:35:43 +02:00
parent e6f287b298
commit d32b2f6a20
5 changed files with 121 additions and 21 deletions

View File

@@ -287,6 +287,28 @@ class MavenBuildWriterTests {
});
}
@Test
void pomWithOptionalDependency() throws Exception {
MavenBuild build = new MavenBuild();
build.setGroup("com.example.demo");
build.setArtifact("demo");
build.dependencies().add("annotation-processor",
MavenDependency
.withCoordinates("org.springframework.boot",
"spring-boot-configuration-processor")
.scope(DependencyScope.COMPILE).optional(true));
generatePom(build, (pom) -> {
NodeAssert dependency = pom.nodeAtPath("/project/dependencies/dependency");
assertThat(dependency).textAtPath("groupId")
.isEqualTo("org.springframework.boot");
assertThat(dependency).textAtPath("artifactId")
.isEqualTo("spring-boot-configuration-processor");
assertThat(dependency).textAtPath("version").isNullOrEmpty();
assertThat(dependency).textAtPath("scope").isNullOrEmpty();
assertThat(dependency).textAtPath("optional").isEqualTo("true");
});
}
@Test
void pomWithNonNullArtifactTypeDependency() throws Exception {
MavenBuild build = new MavenBuild();