I have a simple Java 9 SE project with one dependency on a non-modularized project (chose Weld SE for this example) and I am trying to build it with Maven (clean insta
I think this may help to tell maven to use java 9 :
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
If you specify a module-info.java
file, you will need to declare all the java modules except java.base
you need as you are now using jigsaw.
Using mvn dependency:tree
can help you in populating this but you are not required to use module-info.java
in Java 9.
Including few of the recent updates, I would try and answer this.
UPDATE
Java 9 was released publically on 21.09.2017.
The minimum compatible version of maven-compiler-plugin
in today's date is 3.7.0
.
As already shared by @Tunaki on how you can configure it to build compatible versions for both JDK 1.5 to 8 and JDK 9.
Assuming from the question and comments, you are already aware of automatic modules and placing all the module dependencies on the module path.
Can I tell Maven to put some artifacts on classpath if I know they are not modularized? So that I can avoid the automatic module and the need to declare them?
For artifacts specified in the maven pom <dependencies>
and the ones which are as well not included in the module-info.java
of the current module are ultimately left behind to be accessed from the classpath in form of an unnamed module.
If I stick with automatic module, can I tell Maven to somehow transitively allow anything my dependency needs to bring in? E.g. other parts of Weld, CDI API etc.
No, since the automatic modules do not consist of an explicitly declared module-info.java
, there is no such way of defining requires transitive for any transitive dependency that might be required by the present module.
From one of my past experiences, any Maven transitive dependency as detailed in the dependency:tree
that is needed at compile time by the module would have to be explicitly defined using requires
in the module-info
of the current project.
What is the actual reason, why I need to state, that my project requires modules, which I do not use directly? E.g. weld.environment.common**
You do not need to specify requires
for modules that are not required at compile or runtime by your module.
In case there is a dependency that is not required at runtime but required at compile time by your project, you would need to make sure that you define such module using requires static in your declarations.
I would have preferably practiced a similar approach at present as well, as stated in the answer to should I keep or remove declared dependencies that are also transitive dependencies?