我正在将我们的项目从Java 8迁移到Java 9。
使用:IntelliJ IDEA 2017.2.5
Maven版本:3.5.1
到目前为止,我已经为所有我想迁移的模块创建了module-info.java
。在这里,requires
与java.base
很好地配合使用。但是,所有其他外部模块/依赖项都不行,比如log4j和尚未迁移到Java 9的我们项目中的包。这些包也作为依赖项添加到了POM中。然而,IntelliJ在这里没有报错。
从module-info.java
导航到External Libraries
中对应的JAR文件可以正常工作。
但是,一旦我使用clean install
运行构建,就会出现编译失败:module not found: log4j
。所有其他外部包也是如此。
有什么想法是为什么会出现这个错误吗?我以为非模块化的依赖项将被Java 9转换为自动模块。我做错了什么或者没有理解正确的方法?
这是项目的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>
项目结构:
- 项目SDK:9.0(Java版本“9.0.1”)
- 项目语言级别:9-模块,接口中的私有方法等
- 模块SDK:项目SDK(9.0)
- 模块-->源-->语言级别:9-模块,接口中的私有方法等
- 平台设置:SDK:9.0,JDK主目录路径C:\Program Files\Java\jdk-9.0.1
pom.xml
配置和项目结构?另外,请确保你正在使用与Java9兼容的版本的maven(插件等)。 - Naman
org.apache.maven.plugins
maven-compiler-plugin
9
9
3.7.0
- Naman