多模块父pom的“问题”是,没有复杂的配置文件,它将模块锁定在相同的发布周期中(假设您使用的是Release
Plugin)。
我使用Maven的方式是让一个父pom声明:
- 常见的依赖关系(日志API,JUnit等)。
- 常用插件。
- 本
dependencyManagement
节中的所有依赖项。 - 本
pluginManagement
节中的所有插件。
每个模块都会将父pom作为其父代,但父代对模块一无所知。
这样做的好处来自上面的最后两个项目符号,即“管理”部分。“管理”部分中包含的所有内容都需要在要使用特定依赖项或插件的模块中重新声明。
例如,父母可能看起来像这样:
<project> <groupId>com.example</groupId> <artifactId>parent</artifactId> <version>1.0.00-SNAPSHOT</version> ... <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>2.1</version> </dependency> </dependencyManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </pluginManagement></project>
模块可能看起来像这样:
<project> <parent> <groupId>com.example</groupId> <artifactId>parent</artifactId> <version>1.0.00-SNAPSHOT</version> </parent> <groupId>com.example</groupId> <artifactId>module</artifactId> <version>1.0.00-SNAPSHOT</version> <dependencies> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </dependency> </dependencies> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> </plugin> </plugins></project>
该模块将:
- 有依赖性
org.slf4j:slf4j-api:1.7.7:compile
,junit:junit:4.11:test
和commons-lang:commons-lang:2.6:compile
。 - 有插件
org.apache.maven.plugins:maven-assembly-plugin:2.4



