Java 9 与 Maven - 未找到模块
Java 9 with Maven - modules not found
我正在将我们的项目从 Java 8 迁移到 Java 9。
使用:IntelliJ IDEA 2017.2.5
Maven 版本:3.5.1
到目前为止,我已经为我想要迁移的所有模块创建了 module-info.java
。在这里,requires
与 java.base
配合得很好。但是所有其他外部 modules/dependencies 都没有,比方说我们项目中尚未迁移到 Java 9 的 log4j 和包。这些包也作为依赖项添加到 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,JDKhome路径C:\ProgramFiles\Java\jdk-9.0.1
我遇到了同样的问题。我最终所做的工作是在我的 pom.xml:
中插入 Eclipse 创建的 pom 中的构建元素
<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>
我把这个作为另一个答案,因为不是每个人都可以阅读评论...
对我来说,maven-compiler-plugin
版本是问题所在。似乎模块仅在 3.8.0
.
之后才受支持
下面是我的 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>
我正在将我们的项目从 Java 8 迁移到 Java 9。
使用:IntelliJ IDEA 2017.2.5
Maven 版本:3.5.1
到目前为止,我已经为我想要迁移的所有模块创建了 module-info.java
。在这里,requires
与 java.base
配合得很好。但是所有其他外部 modules/dependencies 都没有,比方说我们项目中尚未迁移到 Java 9 的 log4j 和包。这些包也作为依赖项添加到 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,JDKhome路径C:\ProgramFiles\Java\jdk-9.0.1
我遇到了同样的问题。我最终所做的工作是在我的 pom.xml:
中插入 Eclipse 创建的 pom 中的构建元素<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>
我把这个作为另一个答案,因为不是每个人都可以阅读评论...
对我来说,maven-compiler-plugin
版本是问题所在。似乎模块仅在 3.8.0
.
下面是我的 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>