[
https://issues.apache.org/jira/browse/MCOMPILER-275?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Robert Scholte updated MCOMPILER-275:
-------------------------------------
Attachment: mcompiler-275.patch
{quote}
I've been working on the implementation of this in the maven-compiler-plugin,
but I'm not really pleased with the result.
The problem is that in the worst case scenario we have to work with 3 different
versions of Java:
- The Maven Runtime (set as JAVA_HOME)
- JDK for the module-info.java
- JDK for all other source files.
The example below worked because all three were set to JDK9.
But based on the source/target of 1.6 I cannot predict which JDK is used, only
that it is at least JDK6. Should the plugin switch to another JDK?
And if you want to compile with source/target 1.5 or less, you're in trouble.
There's something called toolchain, where you can specify the JavaHome per
version, but in case of maven-compiler-plugin it assumes that all java-related
plugins and execution blocks want to use the same toolchain through the whole
Maven project.
The good news is that for the maven-jdeps-plugin I improved this part in Maven
3.3.1, since this plugin only works with Java8 and above, which doesn't have to
be the same JDK to compile the sources with. Now you can simple say: I want the
toolchain for version X. This feature needs to be added to the plugin.
That said I think I will write a recipe for this. This is first of all an issue
for library writers who want to have their jar compatible with multiple Java
versions for their end users.
Result: One javac call per execution block as it was meant to be.
{quote}
attachment my work so far, if we want to start a discussion about it.
> Handle separate compilation of module-info.java
> -----------------------------------------------
>
> Key: MCOMPILER-275
> URL: https://issues.apache.org/jira/browse/MCOMPILER-275
> Project: Maven Compiler Plugin
> Issue Type: New Feature
> Reporter: Robert Scholte
> Attachments: mcompiler-275.patch
>
>
> When you want to add a module-info.java file to your project AND want your
> code to be compatible with older java version, then you need to call
> {{javac}} twice.
> To prevent all kinds of magic for selecting the right files to compile with
> the right version of Java it is probably better to just have a separate
> folder for it, e.g. {{src/main/jigsaw}}. I'd prefer to call it 'jigsaw'
> instead of java9, so it'll still makes sense once we're at java16
> On the jigsaw mailinglist they actually expect the module-info file to be in
> the {{src/main/java}} as well. Intuition of users might indeed be to simply
> put it there and let Maven handle it. That should be possible, but it also
> depends if IDEs can handle this too.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)