maven 多模块结构下版本管理

maven 多模块结构下版本管理

父级 pom.xml 文件中进行如下配置:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>pom</packaging>
    <modules>
        <module>buzheng-utils</module>
        <module>bz-common</module>
        <module>bz-api</module>
    </modules>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.bz</groupId>
    <artifactId>common</artifactId>
    <version>${revision}</version>
    <name>buzheng-common</name>

    <profiles>
        <profile>
            <id>prod</id>
            <properties>
                <env>1.0.1-RELEASE</env>
                <fileName>prod</fileName>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <env>1.0.1-SNAPSHOT</env>
                <fileName>test</fileName>
            </properties>
        </profile>
        <profile>
            <id>dev</id>
            <properties>
                <env>1.0.1-SNAPSHOT</env>
                <fileName>dev</fileName>
            </properties>
        </profile>
    </profiles>

    <properties>
        <revision>1.0.1-SNAPSHOT</revision>
        <!-- 其他依赖jar版本管理 -->
        <bz.common.version>${env}</bz.common.version>
        <bz.api.version>${env}</bz.api.version>
        <buzheng-utils.version>${env}</buzheng-utils.version>
    </properties>
    
     <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.bz</groupId>
                <artifactId>bz-common</artifactId>
                <version>${bz.common.version}</version>
            </dependency>

            <dependency>
                <groupId>com.bz</groupId>
                <artifactId>buzheng-utils</artifactId>
                <version>${buzheng-utils.version}</version>
            </dependency>
            
        <dependencies>
      </dependencyManagement>
  </project>  

子级 pomxml 文件

<?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">
    <parent>
        <artifactId>common</artifactId>
        <groupId>com.bz</groupId>
        <version>${revision}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>buzheng-utils</artifactId>
    <version>${buzheng-utils.version}</version>

    <dependencies>
        <dependency>
            <groupId>com.bz</groupId>
            <artifactId>bz-common</artifactId>
        </dependency>
    </dependencies> 
 </project>
<?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">
    <parent>
        <artifactId>common</artifactId>
        <groupId>com.bz</groupId>
        <version>${revision}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>bz-common</artifactId>
    <packaging>jar</packaging>

    <version>${bz.common.version}</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies> 
</project>

api层 pom.xml 文件

<?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">
    <parent>
        <artifactId>common</artifactId>
        <groupId>com.bz</groupId>
        <version>${revision}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>bz-api</artifactId>
    <version>${bz.api.version}</version>


    <properties>
        <java.version>1.8</java.version>

    </properties>

    <dependencies>
        <dependency>
            <groupId>com.bz</groupId>
            <artifactId>bz-common</artifactId>
        </dependency>

        <dependency>
            <groupId>com.bz</groupId>
            <artifactId>buzheng-utils</artifactId>
        </dependency>
        
         <build>
                <finalName>bz-api-${env}</finalName>
                <resources>
                    <!--其他无关的配置文件不打进包,保证安全性-->
                    <resource>
                        <directory>src/main/resources/</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*.xml</include>
                            <include>application.yml</include>
                            <include>application-${fileName}.yml</include>
                        </includes>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
          </build>

    </dependencies>
</project>

idea 打包

根据选择的环境不同打包不同

posted @ 2020-12-29 10:52  _不正  阅读(1102)  评论(0编辑  收藏  举报