Reputation: 105
I have already practiced java 9 module system integration with Maven project. and it seems to work well but I was anxious about backward compatibility of maven module compiled before java 9.
For backward compatibility, JPMS(Java Platform Module System) has Automatic Module Concept. In JPMS, Jar file without module-info.java is regarded as Automatic Module and other java module can use this jar file by using its file name as module name.
In case of integration with maven project, I think additional support for JPMS backward compatibility needed. first, basic jar file and maven jar file is not same structure. second, maven jar file naming is incompatible with rule can be compatibility with JPMS module naming rule. see the below example.
<artifactId>previous-version-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
In above cases, We already uses previous-version-module-0.0.1-SNAPSHOT and want to use this module in new java 9 maven project.
module new.module{
requires previous-version-module-0.0.1-SNAPSHOT
}
but it occur compile error or IDEA tool throw error.
I'm wondering how to use maven jar file which compiled before java 9 in java 9 and maven integration project. I searched some additional module definition rule or maven plugin, I can't find any solution.
Thanks.
Upvotes: 6
Views: 2859
Reputation: 5449
If the module name isn't obvious then you can use jar --file=<jarfile> --describe-module
to see the derived name. Alternatively, use the --list-modules
option, i.e. java -p <jarfile> --list-modules
.
Once you know the module name then you use requires <module>
and it should work. The maven-compiler-plugin puts all dependences on the module path when building a project that has a module-info.java in the source tree.
Upvotes: 6