<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!--由于不是继承,所以必须重新添加 groupId 和 version--> <groupId>net.biancheng.www</groupId> <artifactId>App-Data-lib</artifactId> <version>1.0</version> <!--dependencyManagement 标签用于控制子模块的依赖版本等信息 --> <!-- 该标签只用来控制版本,不能将依赖引入 --> <dependencyManagement> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <!--引用的properties标签中定义的属性 --> <version>1.2.17</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <!--引用的properties标签中定义的属性 --> <version>4.9</version> <!-- <scope>test</scope> --> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <!--引用的properties标签中定义的属性 --> <version>5.1.18</version> <scope>runtime</scope> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <!--引用的properties标签中定义的属性 --> <version>0.9.1</version> </dependency> </dependencies> </dependencyManagement> <!--声明依赖--> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> </project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>net.biancheng.www</groupId> <artifactId>Root</artifactId> <version>1.0</version> <!--定义的父类pom.xml 打包类型使pom --> <packaging>pom</packaging> <properties> <!-- 定义一些 maven 变量 --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <log4j.version>1.2.17</log4j.version> <junit.version>4.9</junit.version> <system.version>1.0</system.version> <mysql.connector.version>5.1.18</mysql.connector.version> <c3p0.version>0.9.1</c3p0.version> </properties> <!--dependencyManagement 标签用于控制子模块的依赖版本等信息 --> <!-- 该标签只用来控制版本,不能将依赖引入 --> <dependencyManagement> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <!--引用的properties标签中定义的变量 --> <version>${log4j.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <!--引用的properties标签中定义的变量 --> <version>${junit.version}</version> <!-- <scope>test</scope> --> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <!--引用的properties标签中定义的变量 --> <version>${mysql.connector.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <!--引用的properties标签中定义的变量 --> <version>${c3p0.version}</version> </dependency> </dependencies> </dependencyManagement> </project>在父模块 Root 中使用 dependencyManagement 元素声明的依赖,既不会给 Root 模块引入依赖,也不会给其子模块引入依赖,但这段配置是可以被继承的。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>App-Core-lib</artifactId> <parent> <groupId>net.biancheng.www</groupId> <artifactId>Root</artifactId> <version>1.0</version> <relativePath>../Root</relativePath> </parent> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> </dependency> </dependencies> <distributionManagement> <repository> <id>bianchengbang_Release_hosted</id> <url>http://localhost:8082/nexus/content/repositories/bianchengbang_Release_hosted/</url> </repository> <snapshotRepository> <id>Snapshot</id> <url>http://localhost:8082/nexus/content/repositories/bianchengbang_Snapshot_hosted/</url> </snapshotRepository> </distributionManagement> </project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>App-Data-lib</artifactId> <parent> <groupId>net.biancheng.www</groupId> <artifactId>Root</artifactId> <version>1.0</version> </parent> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> </project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!--由于不是继承,所以必须重新添加 groupId 和 version--> <groupId>net.biancheng.www</groupId> <artifactId>App-Data-lib</artifactId> <version>1.0</version> <!--定义依赖管理--> <dependencyManagement> <dependencies> <!--导入依赖管理配置--> <dependency> <groupId>net.biancheng.www</groupId> <artifactId>Root</artifactId> <version>1.0</version> <!--依赖范围为 import--> <scope>import</scope> <!--类型一般为pom--> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <!--声明依赖--> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> </project>
本文链接:http://task.lmcjl.com/news/15505.html