Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support version ranges in parent reference #3023

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ private void resolveParentPropertiesAndRepositoriesRecursively(List<Pom> pomAnce
mergeRepositories(pom.getRepositories());

if (pom.getParent() != null) {
Pom parentPom = downloader.download(getValues(pom.getParent().getGav()),
pom.getParent().getRelativePath(), ResolvedPom.this, repositories);
Pom parentPom = resolveParentPom(pom);

for (Pom ancestor : pomAncestry) {
if (ancestor.getGav().equals(parentPom.getGav())) {
Expand Down Expand Up @@ -379,8 +378,7 @@ private void resolveParentDependenciesRecursively(List<Pom> pomAncestry) throws
mergeRequestedDependencies(pom.getDependencies());

if (pom.getParent() != null) {
Pom parentPom = downloader.download(getValues(pom.getParent().getGav()),
pom.getParent().getRelativePath(), ResolvedPom.this, repositories);
Pom parentPom = resolveParentPom(pom);

MavenExecutionContextView.view(ctx)
.getResolutionListener()
Expand All @@ -398,6 +396,24 @@ private void resolveParentDependenciesRecursively(List<Pom> pomAncestry) throws
}
}

private Pom resolveParentPom(Pom pom) throws MavenDownloadingException {
@SuppressWarnings("DataFlowIssue") GroupArtifactVersion gav = getValues(pom.getParent().getGav());
if (gav.getVersion() == null) {
throw new MavenParsingException("Parent version must always specify a version " + gav);
}

VersionRequirement newRequirement = VersionRequirement.fromVersion(gav.getVersion(), 0);
GroupArtifact ga = new GroupArtifact(gav.getGroupId(), gav.getArtifactId());
String newRequiredVersion = newRequirement.resolve(ga, downloader, getRepositories());
if (newRequiredVersion == null) {
throw new MavenParsingException("Could not resolve version for [" + ga + "] matching version requirements " + newRequirement);
}
gav = gav.withVersion(newRequiredVersion);

return downloader.download(gav,
pom.getParent().getRelativePath(), ResolvedPom.this, repositories);
}

private void mergeRequestedDependencies(List<Dependency> incomingRequestedDependencies) {
if (!incomingRequestedDependencies.isEmpty()) {
if (requestedDependencies == null || requestedDependencies.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,34 @@ void transitiveDependencyVersionDeterminedByBom() {
);
}

@Test
void parentVersionRange() {
rewriteRun(
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.managed.test</groupId>
<artifactId>a</artifactId>
<version>1.0.0</version>
<parent>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-parent</artifactId>
<version>[2.9.1,2.10.0)</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
"""
)
);
}

@Test
void guava25() {
rewriteRun(
Expand Down