Skip to content

Commit fa779df

Browse files
authored
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.
1 parent d5c1764 commit fa779df

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

maven-core/src/main/java/org/apache/maven/project/MavenProject.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,15 +1216,27 @@ private void logWarning(String method) {
12161216
return;
12171217
}
12181218

1219-
LOGGER.warn("Direct modification of " + collectionName + " through " + method
1220-
+ "() is deprecated and will not work in Maven 4.0.0. "
1221-
+ "Please use the add/remove methods instead. If you're using a plugin that causes this warning, "
1222-
+ "please upgrade to the latest version and report an issue if the warning persists. "
1219+
String specificMethods = getRecommendedMethods(collectionName);
1220+
LOGGER.warn("Plugin is modifying " + collectionName + " through " + method
1221+
+ "(), which will not work in Maven 4.0.0. "
1222+
+ "Use " + specificMethods + " instead. "
1223+
+ "If using a plugin, please upgrade to the latest version or report the issue to the plugin maintainer. "
12231224
+ "To disable these warnings, set -D" + DISABLE_WARNINGS_PROPERTY + "=true on the command line, "
12241225
+ "in the .mvn/maven.config file, or in project POM properties.");
12251226
// Log a stack trace to help identify the caller
12261227
if (LOGGER.isDebugEnabled()) {
1227-
LOGGER.debug("Stack trace", new Exception("Stack trace"));
1228+
LOGGER.debug("Stack trace for deprecated source root modification:", new Exception("Stack trace"));
1229+
}
1230+
}
1231+
1232+
private String getRecommendedMethods(String collectionName) {
1233+
switch (collectionName) {
1234+
case "compileSourceRoots":
1235+
return "MavenProject.addCompileSourceRoot()/removeCompileSourceRoot() methods";
1236+
case "testCompileSourceRoots":
1237+
return "MavenProject.addTestCompileSourceRoot()/removeTestCompileSourceRoot() methods";
1238+
default:
1239+
return "appropriate MavenProject add/remove methods";
12281240
}
12291241
}
12301242

0 commit comments

Comments
 (0)