1、构建项目中的细节
groupId :the unique identifier of the organization or group that created the project (创建该项目的组织或者小组的唯一标识)
例子:比如我的组织叫做ant,项目名称jeepe ,那么可以将groupid定义为 com.ant.jeepe
artifactId :unique base name of the primary artifact being generated by this project(该项目中的主要子项的唯一基本名称标识)
例子:项目名称jeepe ,项目下的api子模块,可以定义为 jeepe-api
name: 声明了一个对于用户更为友好的项目名称,不是必须的,推荐为每个pom声明name,以方便信息交流,,可以和artifactId 保持一致
2、继承和聚合
2.1、继承是为了解决依赖复用的问题,消除重复配置,比如三个子模块都用到了一个依赖,那么就可以抽离到parent依赖中统一管理。
<?xml version="1.0" encoding="UTF-8"?> <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ant.parent</groupId> <artifactId>ant-parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <name>ant-parent</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <spring-boot.version>2.1.6.RELEASE</spring-boot.version> <dubbo.version>2.7.3</dubbo.version> <dubbo-spring-boot.version>2.7.3</dubbo-spring-boot.version> <curator.famework.version>4.2.0</curator.famework.version> </properties> <distributionManagement> <repository> <id>maven-release</id> <name>Nexus Release Repository</name> <url>http://maven.igper.com/repository/maven-releases/</url> </repository> <snapshotRepository> <id>maven-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://maven.igper.com/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> <version>${javax.mail.version}</version> </dependency> </dependencies> </dependencyManagement> <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> </plugin> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.7</version> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.16</version> </dependency> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.7</version> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>${tkmybatis.version}</version> </dependency> </dependencies> <executions> <execution> <id>Generate MyBatis Artifacts</id> <phase>package</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <!--允许移动生成的文件 --> <verbose>true</verbose> <!-- 是否覆盖 --> <overwrite>false</overwrite> <!-- 自动生成的配置 --> <configurationFile>src/main/resources/mybatis-generater.xml</configurationFile> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
2.2、Maven 的聚合其实就是项目与子项目的表示,其存在的意义在于快速构建项目。
<?xml version="1.0" encoding="UTF-8"?> <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.gpmall.commons</groupId> <artifactId>gpmall-commons</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>commons-tool</module> <module>commons-core</module> <module>commons-lock</module> <module>commons-mq</module> </modules> <distributionManagement> <repository> <id>maven-release</id> <name>Nexus Release Repository</name> <url>http://maven.igper.com/repository/maven-releases/</url> </repository> <snapshotRepository> <id>maven-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://maven.igper.com/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement> <name>gpmall-commons</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> </project>