You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by de...@apache.org on 2025/05/20 11:54:29 UTC
(maven) branch master updated: [MNG-8713] SourceRoot.directory() default value should include the module when present (#2278)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux 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 d03b61d245 [MNG-8713] SourceRoot.directory() default value should include the module when present (#2278)
d03b61d245 is described below
commit d03b61d245510432e024e5b6d632f00f8bbfd4ea
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue May 20 13:54:24 2025 +0200
[MNG-8713] SourceRoot.directory() default value should include the module when present (#2278)
The default directory is `src/${module}/${scope}/${lang}`.
When no module is defined, the previous default is unchanged.
---
.../main/java/org/apache/maven/api/SourceRoot.java | 21 ++++++++++++++++++---
api/maven-api-model/src/main/mdo/maven.mdo | 12 +++++++++---
.../org/apache/maven/impl/DefaultSourceRoot.java | 6 +++++-
3 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java b/api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java
index 732cd0aec7..c60f6befda 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java
@@ -39,11 +39,26 @@ public interface SourceRoot {
* The path is relative to the <abbr>POM</abbr> file.
*
* <h4>Default implementation</h4>
- * The default value is <code>src/{@linkplain #scope() scope}/{@linkplain #language() language}</code>
- * as a relative path. Implementation classes may override this default with an absolute path instead.
+ * The default value depends on whether a {@linkplain #module() module name} is specified in this source root:
+ * <ul>
+ * <li>
+ * If no module name, then the default directory is
+ * <code>src/{@linkplain #scope() scope}/{@linkplain #language() language}</code>.
+ * </li><li>
+ * If a module name is present, then the default directory is
+ * <code>src/{@linkplain #module() module}/{@linkplain #scope() scope}/{@linkplain #language() language}</code>.
+ * </li>
+ * </ul>
+ *
+ * The default value is relative.
+ * Implementation may override with absolute path instead.
*/
default Path directory() {
- return Path.of("src", scope().id(), language().id());
+ Path src = Path.of("src");
+ return module().map(src::resolve)
+ .orElse(src)
+ .resolve(scope().id())
+ .resolve(language().id());
}
/**
diff --git a/api/maven-api-model/src/main/mdo/maven.mdo b/api/maven-api-model/src/main/mdo/maven.mdo
index 0aff238fd2..48df570aec 100644
--- a/api/maven-api-model/src/main/mdo/maven.mdo
+++ b/api/maven-api-model/src/main/mdo/maven.mdo
@@ -2014,9 +2014,15 @@
usage (main code, tests, <i>etc.</i>) is specified by the {@code scope} element.
<h2>Default source directories</h2>
- If no source directories are specified, the defaults are {@code src/${scope}/${lang}} where
- {@code ${scope}} is the value of the {@link #scope} element (typically {@code main} or {@code test}) and
- {@code ${lang}} is the value of the {@link #lang} element (typically {@code java} or {@code resources}).
+ If no source directories are specified, the default values depend on whether module names are specified:
+ <ul>
+ <li>{@code src/${scope}/${lang}} if no module is specified</li>
+ <li>{@code src/${module}/${scope}/${lang}} if a module is specified</li>
+ </ul>
+ where
+ {@code ${scope}} is the value of the {@link #scope} element (typically {@code main} or {@code test}),
+ {@code ${lang}} is the value of the {@link #lang} element (typically {@code java} or {@code resources}),
+ and {@code ${module}} is the optional {@link #module} element.
]]>
</description>
<version>4.1.0+</version>
diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
index 376c579e28..dc89498e86 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
@@ -81,7 +81,11 @@ public DefaultSourceRoot(final Session session, final Path baseDir, final Source
if (value != null) {
directory = baseDir.resolve(value);
} else {
- directory = baseDir.resolve("src").resolve(scope.id()).resolve(language.id());
+ Path src = baseDir.resolve("src");
+ if (moduleName != null) {
+ src = src.resolve(language.id());
+ }
+ directory = src.resolve(scope.id()).resolve(language.id());
}
value = nonBlank(source.getTargetVersion());