Skip to content

Commit 4ca8bcf

Browse files
authored
Treat missing POMs for non-classpath dependencies as warnings (#7163)
Maven itself only logs a warning when a dependency's POM cannot be downloaded ("The POM for ... is missing, no dependency information available") and continues the build. Our resolution was treating this as a fatal error, causing the entire LST build to fail when e.g. tgz dependencies lack a POM in the repository. For non-classpath artifact types (tgz, zip, pom, bom), skip the dependency on download failure instead of accumulating a fatal exception, matching Maven's behavior. Fixes moderneinc/customer-requests#2095
1 parent 84ef752 commit 4ca8bcf

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,13 @@ public List<ResolvedDependency> resolveDependencies(Scope scope, Map<GroupArtifa
11821182
}
11831183
}
11841184
} catch (MavenDownloadingException e) {
1185-
exceptions = MavenDownloadingExceptions.append(exceptions, e.setRoot(dd.getRootDependent().getGav()));
1185+
String type = dd.getDependency().getType();
1186+
if (type != null && !"jar".equals(type) && !"ejb".equals(type)) {
1187+
// Non-classpath artifacts may lack a POM; skip like Maven does
1188+
ctx.getOnError().accept(e);
1189+
} else {
1190+
exceptions = MavenDownloadingExceptions.append(exceptions, e.setRoot(dd.getRootDependent().getGav()));
1191+
}
11861192
}
11871193
}
11881194

rewrite-maven/src/test/java/org/openrewrite/maven/MavenDependencyFailuresTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,46 @@ void unresolvableTransitiveDependencyDueToInvalidPom() {
342342
);
343343
}
344344

345+
@Test
346+
void unresolvableTgzDependencyShouldNotFailBuild() {
347+
rewriteRun(
348+
spec -> spec.executionContext(new InMemoryExecutionContext())
349+
.typeValidationOptions(TypeValidation.builder()
350+
.dependencyModel(false)
351+
.build()),
352+
pomXml(
353+
"""
354+
<project>
355+
<groupId>com.mycompany.app</groupId>
356+
<artifactId>my-app</artifactId>
357+
<version>1</version>
358+
<dependencies>
359+
<dependency>
360+
<groupId>com.example.mongo.osx</groupId>
361+
<artifactId>mongodb-osx-ssl-x86_64</artifactId>
362+
<version>3.6.23</version>
363+
<type>tgz</type>
364+
<scope>test</scope>
365+
</dependency>
366+
<dependency>
367+
<groupId>com.example.mongo.linux</groupId>
368+
<artifactId>mongodb-linux-x86_64</artifactId>
369+
<version>3.6.23</version>
370+
<type>tgz</type>
371+
<scope>test</scope>
372+
</dependency>
373+
</dependencies>
374+
</project>
375+
""",
376+
spec -> spec.afterRecipe(after -> {
377+
// tgz dependencies that can't be downloaded should NOT cause a parse failure
378+
Optional<ParseExceptionResult> maybeParseException = after.getMarkers().findFirst(ParseExceptionResult.class);
379+
assertThat(maybeParseException).isEmpty();
380+
})
381+
)
382+
);
383+
}
384+
345385
private Recipe updateModel() {
346386
return toRecipe(() -> new MavenIsoVisitor<>() {
347387
@Override

0 commit comments

Comments
 (0)