父工程的pom.xml中可能存在的标签
<!-- 指定打包类型,如果打包类型为jar,可以省略不指定,如果为war或者是pom,必须显示指定 --> <packaging>pom</packaging>
<!-- 依赖的管理--子工程中都要使用到的jar包 【1】--> <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.9</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement>
<!-- 聚合 --> <modules> <module>../MakeFriend</module> <module>../HelloFriend</module> <module>../OurFriend</module> <module>../Hello</module> </modules> |
子工程的pom.xml中可能会用到标签
<!-- 模块版本 --> <modelVersion>4.0.0</modelVersion>
<!-- 坐标 --> <!-- <groupId>com.test.maven</groupId> --> <artifactId>HelloFriend</artifactId> <!-- <version>0.0.1-SNAPSHOT</version> -->
<!-- 模块名/ 项目名/ 工程名 --> <name>Hello</name>
<!-- 继承【1】 要先声明继承--> <parent> <groupId>com.test.maven</groupId> <artifactId>Parent</artifactId> <version>0.0.1-SNAPSHOT</version> <!-- 指定从当前子工程的pom.xml文件出发,查找父工程的pom.xml的路径 --> <relativePath>../Parent/pom.xml</relativePath> </parent> <!-- jar包的依赖 【1】继承父工程的jar包,可省略groupId和version --> <dependencies> <!-- Junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <!-- <version>4.0</version> --> <scope>test</scope> </dependency>
<!—HelloFriend依赖Hello,排除其中的一些依赖 --> <dependency> <!-- 依赖的另一个工程--> <groupId>com.test.maven</groupId> <artifactId>Hello</artifactId> <version>0.0.1-SNAPSHOT</version> <scope>compile</scope> <!-- 依赖的排除 --> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </exclusion> </exclusions> </dependency> <!-- log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> <scope>compile</scope> </dependency>
<!-- 声明配置【2】 --> <properties> <!-- 定义表示spring版本的变量 --> <spring-version>4.0.0.RELEASE</spring-version> </properties> <!-- Spring-core 【2】--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring-version}</version> </dependency> </dependencies>
<build> <plugins> <!-- 解决maven test命令时console出现中文乱码乱码 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.7.2</version> <configuration> <forkMode>once</forkMode><!--在一个进程中进行所有测试 ; 默认值:once --> <argLine>-Dfile.encoding=UTF-8</argLine> </configuration> </plugin> </plugins> </build> |