Maven-构建配置文件

1.profiles

我们的项目会存在不同的运行环境,比如开发环境、测试环境、生产环境,而我们的项目在不同的环境中,有的配置可能会不一样。

需要通过profiles配置

配置如下

<profiles>
    <profile>
      <id>dev</id> <!--不同环境Profile的唯一id-->
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <env>dev</env>
      </properties>
    </profile>
    <profile>
      <id>fat</id>
      <properties>
        <env>fat</env>
      </properties>
    </profile>
 </profiles>

各种环境

  • dev 开发环境
  • fat 工厂验收测试
  • uat (User Acceptance Test)用户接受度测试 即验收测试,所以UAT环境主要是用来作为客户体验的环境。
  • prod 生产环境
  • pt 性能测试
  • newuat
  • master 线上环境(生产环境)

2.激活方式

  • 1.使用maven打包时通过-P参数,-P后跟上profile的唯一id,如

    mvn clean package -Pdev
    
  • 2.通过pom文件里的activation属性

    <profile>
        <id>prod</id>
        <properties>
            <profiles.active>prod</profiles.active>
        </properties>
        <!--activation用来指定激活方式,可以根据jdk环境,环境变量,文件的存在或缺失-->
        <activation>
            <!--配置默认激活-->
            <activeByDefault>true</activeByDefault>
            <!--当jdk环境版本1.5或以上时,此profile被激活-->
            <jdk>[1.5,)</jdk>
            <!--根据当前操作系统-->
            <os>
                <name>Windows XP</name>
                <family>Windows</family>
                <arch>x86</arch>
                <version>5.1.2600</version>
            </os>
            <!--通过系统环境变量,name-value自定义-->
            <property>
                <name>env</name>
                <value>test</value>
            </property>
            <!--通过文件的存在或缺失-->
            <file>
                <missing>target/generated-sources/axistools/wsdl2java/
                    com/companyname/group</missing>
                <exists/>
            </file>
        </activation>
    </profile>
    
    
  • 3.settings.xml中使用activeProfiles指定

    settings.xml 中的profile 元素是 pom.xml中 profile 元素的裁剪版本。它包含了 activation, repositories , pluginRepositories 和 properties元素。这里的profile元素只包含这四个子元素是因为这里只关心构建系统这个整体(这正是 settings.xml文件的角色定位),而非单独的项目对象模型设置。

    如果一个settings中的profile被激活,它的值会覆盖任何其它定义在POM中或者profile.xml中的带有相同id的profile。

    <activeProfiles>
      <activeProfile>carkey-repo-profile</activeProfile>
      <activeProfile>s3s3l-profile</activeProfile>
    </activeProfiles>
    <profile>
      <id>carkey-repo-profile</id>
      <repositories>
          <repository>
              <id>snapshot-repo</id>
              <url></url>
              <releases>
                  <enabled>false</enabled>
              </releases>
              <snapshots>
                  <enabled>true</enabled>
                  <updatePolicy>always</updatePolicy>
              </snapshots>
          </repository>
      </repositories>
    </profile>
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值