Maven多环境构建

Maven支持让我们配置多套环境,每套环境中可以指定自己的maven属性,

profiles元素支持定义多套环境的配置信息,配置如下用法:

<profiles>
    <!-- 开发环境使用的配置 -->
    <profile>
        <id>dev</id>
        <activation>
            <!--默认激活当前配置-->
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <jdbc.url>jdbc:mysql://192.168.10.128:3306/dev?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
            <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
            <jdbc.username>root</jdbc.username>
            <jdbc.password>123456</jdbc.password>

            <jdbc2.url>jdbc:mysql://192.168.10.128:3306/dev2?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc2.url>
            <jdbc2.driver>com.mysql.jdbc.Driver</jdbc2.driver>
            <jdbc2.username>root</jdbc2.username>
            <jdbc2.password>123456</jdbc2.password>
        </properties>
    </profile>
    <!-- 测试环境使用的配置 -->
    <profile>
        <id>test</id>
        <properties>
            <jdbc.url>jdbc:mysql://192.168.10.128:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
            <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
            <jdbc.username>root</jdbc.username>
            <jdbc.password>123456</jdbc.password>
        </properties>
    </profile>
    <!-- 线上环境使用的配置 -->
    <profile>
        <id>prod</id>
        <properties>
            <jdbc.url>jdbc:mysql://192.168.10.128:3306/prod?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
            <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
            <jdbc.username>root</jdbc.username>
            <jdbc.password>123456</jdbc.password>
        </properties>
    </profile>
</profiles>

 

另外一种多环境选择方式

<profiles>
    <!-- 开发环境使用的配置 -->
    <profile>
        <id>dev</id>
        <activation>
            <!--默认激活当前配置-->
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <filters>
                <filter>src/main/resources/jdbc-dev.properties</filter>
            </filters>
        </build>
    </profile>
    <!-- 测试环境使用的配置 -->
    <profile>
        <id>test</id>
        <activation>
            <!--默认激活当前配置-->
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <filters>
                <filter>src/main/resources/jdbc-test.properties</filter>
            </filters>
        </build>
    </profile>
    <!-- 线上环境使用的配置 -->
    <profile>
        <id>prod</id>
        <build>
            <filters>
                <filter>src/main/resources/jdbc-prod.properties</filter>
            </filters>
        </build>
    </profile>
</profiles>

posted on   companion  阅读(103)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
历史上的今天:
2019-02-02 Quartz使用一
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示