Hello all
I would like to propose a change in the way to specify source directory
in a POM file. Currently, it can be done as below:
<build>
<sourceDirectory>foo</sourceDirectory>
I would like to propose a structure more like below (similar to
org.codehaus.mojo:build-helper-maven-plugin:add-source). In this
proposal, I'm using XML attributes only for brevity. The use of
attributes versus enclosed elements is not the topic of this email.
<sources>
<source dir="foo" version="11"/>
<source dir="bar" version="11"/> <!-- Can repeat the same version for
specifying many source directories. -->
<source dir="biz" version="17"/>
</sources>
The 'version' attributes in above example is optional, but if present
the Maven compiler and JAR plugins would use this information for
building a multi-version JAR files. We could also imagine an 'exclude'
attribute expecting a Boolean value, for making easy to filter the list
of source directories depending on property values.
I make this proposal also because I would like a 'module' attribute.
Since Java 9, each module can have its own source directory in a single
compilation unit. Example:
<sources>
<source dir="src/org.myproject.foo/main" module="org.myproject.foo"/>
<source dir="src/org.myproject.bar/main" module="org.myproject.bar"/>
<source dir="src/org.myproject.biz/main" module="org.myproject.biz"/>
</sources>
A directory structure like above example is known as Module Source
Hierarchy, but with directory enumerated explicitly instead of using the
"--module-source-path src/*/main" pattern. Some may said that the above
should be separated Maven modules. But to my knowledge, it is impossible
to compile [1] with separated Maven modules without compiler warnings or
fatal errors (of course without disabling the warnings). That
demonstration at [1] was done for Gradle, but the exact same problem
applies to Maven.
Martin
[1]https://github.com/Geomatys/MavenModulepathBug/tree/cyclic-graph