Skip to content

Commit

Permalink
Maven runtime dependency is on the compile scope (#4273)
Browse files Browse the repository at this point in the history
* Runtime dependency becomes compile scope dependency issue fix

* Polish

* Polish

* Polish text block in unit test

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove duplicate closing `</project>` tag from test

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
3 people authored Jun 20, 2024
1 parent 7a1b9c6 commit 22ac272
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ public List<ResolvedDependency> resolveDependencies(Scope scope, Map<GroupArtifa
for (Dependency requestedDependency : getRequestedDependencies()) {
Dependency d = getValues(requestedDependency, 0);
Scope dScope = Scope.fromName(d.getScope());
if (dScope == scope || dScope.isInClasspathOf(scope)) {
if (dScope == scope || dScope.transitiveOf(scope) == scope) {
dependenciesAtDepth.add(new DependencyAndDependent(requestedDependency, Scope.Compile, null, requestedDependency, this));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3008,4 +3008,34 @@ void transitiveDependencyManagement() {
)
);
}

@Test
void runtimeClasspathOnly() {
rewriteRun(
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>cache-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.5</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
""",
spec -> spec.afterRecipe(pomXml -> {
MavenResolutionResult resolution = pomXml.getMarkers().findFirst(MavenResolutionResult.class).orElseThrow();
assertThat(resolution.findDependencies("org.glassfish.jaxb", "jaxb-runtime", Scope.Runtime)).isNotEmpty();
assertThat(resolution.findDependencies("org.glassfish.jaxb", "jaxb-runtime", Scope.Compile)).isEmpty();
assertThat(resolution.findDependencies("jakarta.xml.bind", "jakarta.xml.bind-api", Scope.Compile)).isEmpty();
})
)
);
}
}

0 comments on commit 22ac272

Please sign in to comment.