Skip to content

Commit c0813a2

Browse files
authored
[MNG-7838] Fix usage of older packaged artifacts from project local repository (#1199)
1 parent b370e5e commit c0813a2

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

maven-core/src/main/java/org/apache/maven/ReactorReader.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public File findArtifact(Artifact artifact) {
101101
MavenProject project = getProject(artifact);
102102

103103
if (project != null) {
104-
File file = findArtifact(project, artifact);
104+
File file = findArtifact(project, artifact, true);
105105
if (file == null && project != project.getExecutionProject()) {
106-
file = findArtifact(project.getExecutionProject(), artifact);
106+
file = findArtifact(project.getExecutionProject(), artifact, true);
107107
}
108108
return file;
109109
}
@@ -133,7 +133,7 @@ public List<String> findVersions(Artifact artifact) {
133133
.getOrDefault(artifact.getArtifactId(), Collections.emptyMap())
134134
.values()
135135
.stream()
136-
.filter(p -> Objects.nonNull(findArtifact(p, artifact)))
136+
.filter(p -> Objects.nonNull(findArtifact(p, artifact, false)))
137137
.map(MavenProject::getVersion)
138138
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
139139
}
@@ -148,30 +148,30 @@ public Model findModel(Artifact artifact) {
148148
// Implementation
149149
//
150150

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

157-
// First check in the project local repository
158-
File packagedArtifactFile = findInProjectLocalRepository(artifact);
159-
if (packagedArtifactFile != null
160-
&& packagedArtifactFile.exists()
161-
&& isPackagedArtifactUpToDate(project, packagedArtifactFile)) {
162-
return packagedArtifactFile;
163-
}
164-
165157
// Get the matching artifact from the project
166158
Artifact projectArtifact = findMatchingArtifact(project, artifact);
167159
if (projectArtifact != null) {
168160
// If the artifact has been associated to a file, use it
169-
packagedArtifactFile = projectArtifact.getFile();
161+
File packagedArtifactFile = projectArtifact.getFile();
170162
if (packagedArtifactFile != null && packagedArtifactFile.exists()) {
171163
return packagedArtifactFile;
172164
}
173165
}
174166

167+
// Check in the project local repository
168+
File packagedArtifactFile = findInProjectLocalRepository(artifact);
169+
if (packagedArtifactFile != null
170+
&& packagedArtifactFile.exists()
171+
&& (!checkUptodate || isPackagedArtifactUpToDate(project, packagedArtifactFile))) {
172+
return packagedArtifactFile;
173+
}
174+
175175
if (!hasBeenPackagedDuringThisSession(project)) {
176176
// fallback to loose class files only if artifacts haven't been packaged yet
177177
// and only for plain old jars. Not war files, not ear files, not anything else.

0 commit comments

Comments
 (0)