Building jar targeting multiple Java versions, including 9
rfscholte at apache.org
Fri Aug 26 12:06:34 UTC 2016
On Fri, 26 Aug 2016 13:31:47 +0200, Alan Bateman <Alan.Bateman at oracle.com>
> On 26/08/2016 11:49, Robert Scholte wrote:
>> I'm struggling with this issue too.
>> I would have liked to see all the files under src/main/java, but since
>> module-info cannot be compiled at the same time as the other files we
>> need to do some extra things:
>> Possible solutions:
>> - Keep them all in the same folder but let Maven do 2 javac executions,
>> auto-selecting the right files. I don't like this kind of magic and
>> when the configuration of the maven-compiler-plugin becomes complex,
>> there's a chance the magic is doing it wrong.
>> - Introduce an extra sourcefolder. This is by far the most clean
>> solution and with good documentation we should be able to explain this.
>> I've created MCOMPILER-275 to implement this new feature.
> The intention is that the module-info.java be in the root directory and
> I could imagine it confusing developers if they have to edit it in a
> separate source tree. I also worry that it would give the impression
> that a separate source tree is the right way to structure the source
> code. I'm also not sure how it would work in the IDE. Then we have the
> issue that the src and output tree no longer matching, that could be
> confusing too. Then we have the question of projects targeting >= JDK 9
> where I assume you would have the module-info.java in the root directory.
> How difficult would it be for the compiler plugin to special case
> module-info.java when compiling for an older release? Would there be
> something in the POM to indicate whether the project produces a module,
> as a modular JAR?
The maven-compiler-plugin has the option of includes/excludes (the files
to compile), so yes it is possible to do this.
But it implies that the plugin will be in control.
There is already some logic based on the existence of a module-info file,
which causes to switch from classpath to modulepath. So far there was no
need for extra configuration and I hope it is not required in this case.
I expect the challenge to be a lot bigger for IDEs.
More information about the jigsaw-dev