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

[MNG-7838] Fix usage of older packaged artifacts from project local repository #1199

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
26 changes: 13 additions & 13 deletions maven-core/src/main/java/org/apache/maven/ReactorReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public File findArtifact(Artifact artifact) {
MavenProject project = getProject(artifact);

if (project != null) {
File file = findArtifact(project, artifact);
File file = findArtifact(project, artifact, true);
if (file == null && project != project.getExecutionProject()) {
file = findArtifact(project.getExecutionProject(), artifact);
file = findArtifact(project.getExecutionProject(), artifact, true);
}
return file;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public List<String> findVersions(Artifact artifact) {
.getOrDefault(artifact.getArtifactId(), Collections.emptyMap())
.values()
.stream()
.filter(p -> Objects.nonNull(findArtifact(p, artifact)))
.filter(p -> Objects.nonNull(findArtifact(p, artifact, false)))
.map(MavenProject::getVersion)
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
Expand All @@ -148,30 +148,30 @@ public Model findModel(Artifact artifact) {
// Implementation
//

private File findArtifact(MavenProject project, Artifact artifact) {
private File findArtifact(MavenProject project, Artifact artifact, boolean checkUptodate) {
// POMs are always returned from the file system
if ("pom".equals(artifact.getExtension())) {
return project.getFile();
}

// First check in the project local repository
File packagedArtifactFile = findInProjectLocalRepository(artifact);
if (packagedArtifactFile != null
&& packagedArtifactFile.exists()
&& isPackagedArtifactUpToDate(project, packagedArtifactFile)) {
return packagedArtifactFile;
}

// Get the matching artifact from the project
Artifact projectArtifact = findMatchingArtifact(project, artifact);
if (projectArtifact != null) {
// If the artifact has been associated to a file, use it
packagedArtifactFile = projectArtifact.getFile();
File packagedArtifactFile = projectArtifact.getFile();
if (packagedArtifactFile != null && packagedArtifactFile.exists()) {
return packagedArtifactFile;
}
}

// Check in the project local repository
File packagedArtifactFile = findInProjectLocalRepository(artifact);
if (packagedArtifactFile != null
&& packagedArtifactFile.exists()
&& (!checkUptodate || isPackagedArtifactUpToDate(project, packagedArtifactFile))) {
return packagedArtifactFile;
}

if (!hasBeenPackagedDuringThisSession(project)) {
// fallback to loose class files only if artifacts haven't been packaged yet
// and only for plain old jars. Not war files, not ear files, not anything else.
Expand Down