【发布时间】:2018-06-22 01:58:36
【问题描述】:
我正在将我们的项目从 Java 8 迁移到 Java 9。
使用:IntelliJ IDEA 2017.2.5
Maven 版本:3.5.1
到目前为止,我为所有要迁移的模块创建了module-info.java。在这里,requires 与java.base 配合得很好。但是所有其他外部模块/依赖项都没有,例如 log4j 和我们项目中尚未迁移到 Java 9 的包。这些包也作为依赖项添加到 POM 中。但是,IntelliJ 不会在这里抛出错误。
Navigation from module-info.java to the corresponding JAR in External Libraries works.
但是,一旦我使用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(插件等)。 -
谢谢,空指针。更新了问题,希望对您有所帮助。
-
您的 maven-compiler-plugin 版本和配置细节看起来很奇怪。
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>9</source> <target>9</target> </configuration> <version>3.7.0</version> </plugin> -
你有“需要 log4j;”吗?在你的 module-info.java 中?
标签: maven intellij-idea maven-3 java-9