This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-3.9.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-3.9.x by this push:
new fa779df0a7 Improve source root modification warning message (#11105)
fa779df0a7 is described below
commit fa779df0a792f0794a3176889b25e63a938f8cf3
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Sep 17 12:59:10 2025 +0200
Improve source root modification warning message (#11105)
- Make warning message more specific by showing exact method names to use
- Change from 'Direct modification' to 'Plugin is modifying' for clarity
- Provide specific method recommendations
(addCompileSourceRoot/removeCompileSourceRoot, etc.)
- Encourage reporting issues to plugin maintainers for ecosystem health
- Improve debug stack trace description
- Address concerns raised in MNG-11089 about message clarity and
actionability
The improved message is more helpful for both end users and plugin
developers
while maintaining the important guidance on disabling warnings.
---
.../org/apache/maven/project/MavenProject.java | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git
a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
index 29a18ff0b2..72ca2214d2 100644
--- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
+++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
@@ -1216,15 +1216,27 @@ private void logWarning(String method) {
return;
}
- LOGGER.warn("Direct modification of " + collectionName + " through
" + method
- + "() is deprecated and will not work in Maven 4.0.0. "
- + "Please use the add/remove methods instead. If you're
using a plugin that causes this warning, "
- + "please upgrade to the latest version and report an
issue if the warning persists. "
+ String specificMethods = getRecommendedMethods(collectionName);
+ LOGGER.warn("Plugin is modifying " + collectionName + " through "
+ method
+ + "(), which will not work in Maven 4.0.0. "
+ + "Use " + specificMethods + " instead. "
+ + "If using a plugin, please upgrade to the latest version
or report the issue to the plugin maintainer. "
+ "To disable these warnings, set -D" +
DISABLE_WARNINGS_PROPERTY + "=true on the command line, "
+ "in the .mvn/maven.config file, or in project POM
properties.");
// Log a stack trace to help identify the caller
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Stack trace", new Exception("Stack trace"));
+ LOGGER.debug("Stack trace for deprecated source root
modification:", new Exception("Stack trace"));
+ }
+ }
+
+ private String getRecommendedMethods(String collectionName) {
+ switch (collectionName) {
+ case "compileSourceRoots":
+ return
"MavenProject.addCompileSourceRoot()/removeCompileSourceRoot() methods";
+ case "testCompileSourceRoots":
+ return
"MavenProject.addTestCompileSourceRoot()/removeTestCompileSourceRoot() methods";
+ default:
+ return "appropriate MavenProject add/remove methods";
}
}