This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 9b20cb44db Improve error message for unresolved expressions (#11615)
9b20cb44db is described below
commit 9b20cb44db9b1b44b72725bef827a0e719cef056
Author: 高春晖 <[email protected]>
AuthorDate: Sun Feb 15 19:44:44 2026 +0800
Improve error message for unresolved expressions (#11615)
* Improve error message for unresolved expressions
Signed-off-by: 高春晖 <[email protected]>
* Fix Spotless formatting violations
Adjust if statement formatting to comply with project code style:
- Split OR conditions onto separate lines with proper indentation
- Ensures consistency with Spotless formatting rules
* Trigger CI re-run
* Trigger CI re-run (flaky test)
Signed-off-by: 高春晖 <[email protected]>
---------
Signed-off-by: 高春晖 <[email protected]>
---
.../maven/impl/DefaultDependencyResolver.java | 60 +++++++++++++++++++++-
1 file changed, 59 insertions(+), 1 deletion(-)
diff --git
a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolver.java
b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolver.java
index 4e955f0901..f2dab23112 100644
---
a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolver.java
+++
b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultDependencyResolver.java
@@ -174,7 +174,8 @@ public DependencyResolverResult collect(@Nonnull
DependencyResolverRequest reque
session.getNode(result.getRoot(),
request.getVerbose()),
0);
} catch (DependencyCollectionException e) {
- throw new DependencyResolverException("Unable to collect
dependencies", e);
+ String enhancedMessage = enhanceCollectionError(e,
collectRequest);
+ throw new DependencyResolverException(enhancedMessage, e);
}
} finally {
RequestTraceHelper.exit(trace);
@@ -274,4 +275,61 @@ public DependencyResolverResult
resolve(DependencyResolverRequest request)
private static DependencyResolverException cannotReadModuleInfo(final Path
path, final IOException cause) {
return new DependencyResolverException("Cannot read module information
of " + path, cause);
}
+
+ private static boolean containsUnresolvedExpression(String value) {
+ return value != null && value.contains("${") && value.contains("}");
+ }
+
+ private static String enhanceCollectionError(DependencyCollectionException
e, CollectRequest request) {
+ if (e.getMessage() != null && e.getMessage().contains("Invalid Collect
Request")) {
+ StringBuilder enhanced = new StringBuilder();
+ enhanced.append("Failed to collect dependencies");
+
+ org.eclipse.aether.graph.Dependency root = request.getRoot();
+ if (root != null && root.getArtifact() != null) {
+ org.eclipse.aether.artifact.Artifact artifact =
root.getArtifact();
+ String groupId = artifact.getGroupId();
+ String artifactId = artifact.getArtifactId();
+ String version = artifact.getVersion();
+
+ if (containsUnresolvedExpression(groupId)
+ || containsUnresolvedExpression(artifactId)
+ || containsUnresolvedExpression(version)) {
+ enhanced.append(" due to unresolved expression(s) in
dependency: ")
+ .append(groupId)
+ .append(":")
+ .append(artifactId)
+ .append(":")
+ .append(version)
+ .append(".\n")
+ .append("Please check that all properties are
defined in your POM or settings.xml.");
+ return enhanced.toString();
+ }
+ }
+
+ for (org.eclipse.aether.graph.Dependency dep :
request.getDependencies()) {
+ if (dep != null && dep.getArtifact() != null) {
+ org.eclipse.aether.artifact.Artifact artifact =
dep.getArtifact();
+ String groupId = artifact.getGroupId();
+ String artifactId = artifact.getArtifactId();
+ String version = artifact.getVersion();
+
+ if (containsUnresolvedExpression(groupId)
+ || containsUnresolvedExpression(artifactId)
+ || containsUnresolvedExpression(version)) {
+ enhanced.append(" due to unresolved expression(s) in
dependency: ")
+ .append(groupId)
+ .append(":")
+ .append(artifactId)
+ .append(":")
+ .append(version)
+ .append(".\n")
+ .append("Please check that all properties are
defined in your POM or settings.xml.");
+ return enhanced.toString();
+ }
+ }
+ }
+ }
+ return e.getMessage();
+ }
}