您的位置:首页 > 其它

【转】maven命令-P 参数引发的思考

2017-07-11 16:34 323 查看

序言:

maven 命令:clean package -Dmaven.test.skip=true -P product

1.命令很简单是:清class文件,打包构建,跳过测试,注意最后一个 -P product,-P maven 会激活项目下的pom.xml配置的<profiles>标签下id为product

[html] view plain copy

<profiles>

<profile>

<id>product</id>

<properties>

<env>product</env>

</properties>

</profile>

</profiles>

2.使用占位符上面配置定义的${env}进行资源过滤

[html] view plain copy

<bulid><!--指定资源目录 配置是否启用资源过滤(就是是否启用占位符替换)-->

<resources>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

<includes>

<include>logback.xml</include>

</includes>

</resource>

</rwsources>

<!-- 变量来源 -->

<filters>

<filter>src/main/resources/log-profile-${env}.properties</filter>

</filters>

</build>

3.通过maven的setting设置,激活profile(第二种全局的激活方式,可以忽略,如果都使用<env>,这个的值会被覆盖)

[html] view plain copy

<activeProfiles>

<activeProfile>product</activeProfile>

</activeProfiles>

总结:
1. -P 参数 配合资源过滤Filter,最终使用了 src/main/resources/log-profile-product.properties 文件
2. 这个配置文件就是为可以使用占位符的logback.xml文件提供对应 的值

3. 激活profile和spring的profile有点志同道合,maven的这个配置激活还可以用到很多方面,例如开发环境用快照仓库(版本),生产用发布仓库
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: