我在Maven中有一个相当简单的项目结构,包含子模块:
/
-pom.xml
-Utils/
-pom.xml
Run Code Online (Sandbox Code Playgroud)
在/pom.xml我定义所有子模块的属性,如库版本或插件配置:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>project</groupId>
<artifactId>main</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>Utils</module>
</modules>
<properties>
<java.version>10</java.version>
<vertx.version>3.5.0</vertx.version>
</properties>
</project>
Run Code Online (Sandbox Code Playgroud)
在/Utils/pom.xml我声明子模块及其依赖项:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>project</groupId>
<artifactId>main</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>Utils</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<version>${vertx.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
我宣布一个module-info.java文件:
module util {
requires vertx.core;
}
Run Code Online (Sandbox Code Playgroud)
当我在IDE中打开项目时,它按预期工作,我可以从模块中的vertx.core包访问类,Utils并在那里列出所有依赖项.但是,当我尝试通过调用maven进行编译时mvn clean compile,似乎依赖关系不在类路径中:
[INFO] Compiling …Run Code Online (Sandbox Code Playgroud)