父pom文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <groupId>com.backend</groupId>
  5. <artifactId>scaffold</artifactId>
  6. <!--使用revision标签来关联统一版本号-->
  7. <version>${revision}</version>
  8. <name>scaffold</name>
  9. <modelVersion>4.0.0</modelVersion>
  10. <packaging>pom</packaging>
  11. <parent>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-parent</artifactId>
  14. <version>2.2.1.RELEASE</version>
  15. </parent>
  16. <modules>
  17. <module>gateway</module>
  18. <module>common</module>
  19. </modules>
  20. <properties>
  21. <!--使用revision标签定义项目版本-->
  22. <revision>0.0.1-SNAPSHOT</revision>
  23. </properties>
  24. <!--父pom定义的依赖会被子模块依赖 所以父pom中定义所有子模块需要依赖的jar包-->
  25. <dependencies>
  26. </dependencies>
  27. <!--父pom定义的依赖管理会约束子模块相关jar包的依赖版本,此处定义一些依赖但并不会被所有子模块自动依赖
  28. 子模块根据需要自动引入所需依赖的坐标-->
  29. <dependencyManagement>
  30. </dependencyManagement>
  31. <build>
  32. <plugins>
  33. <plugin>
  34. <!--该插件用于install/deploy时替换版本号,服务revision标签的使用-->
  35. <groupId>org.codehaus.mojo</groupId>
  36. <artifactId>flatten-maven-plugin</artifactId>
  37. <version>1.1.0</version>
  38. <configuration>
  39. <updatePomFile>true</updatePomFile>
  40. <flattenMode>resolveCiFriendliesOnly</flattenMode>
  41. </configuration>
  42. <executions>
  43. <execution>
  44. <id>flatten</id>
  45. <phase>process-resources</phase>
  46. <goals>
  47. <goal>flatten</goal>
  48. </goals>
  49. </execution>
  50. <execution>
  51. <id>flatten.clean</id>
  52. <phase>clean</phase>
  53. <goals>
  54. <goal>clean</goal>
  55. </goals>
  56. </execution>
  57. </executions>
  58. </plugin>
  59. </plugins>
  60. </build>
  61. </project>

子pom—common

<?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>
    <artifactId>common</artifactId>
    <packaging>jar</packaging>

    <parent>
        <artifactId>scaffold</artifactId>
        <groupId>com.backend</groupId>
        <version>${revision}</version>
    </parent>

    <dependencies>

    </dependencies>

</project>

子pom-gateway(gateway模块依赖common模块)

<?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>
    <artifactId>gateway</artifactId>
    <packaging>jar</packaging>

    <parent>
        <groupId>com.backend</groupId>
        <artifactId>scaffold</artifactId>
        <version>${revision}</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>com.backend</groupId>
            <artifactId>common</artifactId>
            <!--使用${project.version}标签来引入common模块-->
            <version>${project.version}</version>
        </dependency>
    </dependencies>

</project>