I'm working on the migration of our project from Java 8 to Java 9.
Using: IntelliJ IDEA 2017.2.5
Maven version: 3.5.1
So far, I created module-info.java
for all the modules I'd like to migrate. Here, requires
works well with java.base
. But all other external modules/dependencies do not, let's say for example log4j and packages from our project that are not yet migrated to Java 9. These packages are also added as dependencies in the POM. However, IntelliJ doesn't throw an error here.
Navigation from module-info.java
to the corresponding JAR in External Libraries
works.
But as soon as I run the build with clean install
, there is a compilation failure: module not found: log4j
. Same with all other external packages.
Any idea why this error occurs? I thought non-modular dependencies will be turned into an automatic module by Java 9. What am I doing wrong or didn't understand the right way?
Here is the project's POM:
<groupId>de.project</groupId>
<artifactId>basicProject</artifactId>
<version>1.0</version>
<name>Basic Project</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
<compilerVersion>3.7.0</compilerVersion>
</configuration>
<version>3.5.1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>../output/intern/</outputDirectory>
<resources>
<resource>
<directory>intern</directory>
<includes>
<include>loggingConfig.xml</include>
</includes>
<!--<filtering>true</filtering>-->
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
</properties>
<repositories>
<repository>
<id>some_repository</id>
<name>somerepos</name>
<url>http://some.rep.de/plugin/repo/everything</url>
</repository>
</repositories>
<dependencies>
<!--the first project -->
<dependency>
<groupId>de.project</groupId>
<artifactId>firstProject</artifactId>
<version>1.2</version>
</dependency>
<!--the second project -->
<dependency>
<groupId>de.project</groupId>
<artifactId>secondProject</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>de.project</groupId>
<artifactId>thirdProject</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>de.project</groupId>
<artifactId>fourthProject</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.someitextpdf</groupId>
<artifactId>someitextpdf</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>io.github.lzf0349</groupId>
<artifactId>jdatepicker</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<!--libs for testing -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>5.2.1.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
Project structure:
I make this another answer because not everyone may read the comments...
For me the maven-compiler-plugin
version was the problem. It seems modules are only supported since 3.8.0
.
So here are the parts from my pom.xml
:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
I had the same problem. What I finally did and worked was to insert the build-element from a pom created by Eclipse in my pom.xml:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</execution>
</executions>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With