Maven 命令 Springboot Maven 多环境打包

  1. maven打包跳过测试环境的命令:

答:

mvn package -DskipTests=true

其中-D代表定义一个环境属性,格式如下(有多个属性可以用空格隔开):

mvn -DpropertyName=propertyValue

或者也可以用像下面的命令。这个会把编译过程也跳过

mvn package -Dmaven.test.skip=true 
  1. maven打包不同环境需要什么配置?要打包不同环境的配置需要什么命令?
    答:需要配置profile属性,前者用来定义命令对应的profile,后者用来确定命令对应文件的位置。同时需要配置对应环境的application.properties或者application.dev。如下:
    <profiles>
        <profile>
            <!-- profile的id -->
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <!-- 测试环境 -->
            <id>beta</id>
            <properties>
                <profiles.active>beta</profiles.active>
            </properties>
        </profile>
        <profile>
            <!-- 生产环境 -->
            <id>pro</id>
            <properties>
                <profiles.active>pro</profiles.active>
            </properties>
        </profile>
    </profiles>

我们的不同环境的配置文件为:application-dev.properties ,application-beta.properties,application-pro.properties

然后我们再application.properties里面配置好下面这一行(注意profiles.active要和定义在profile里面的相同)

## 指定执行环境
spring.profiles.active = @profiles.active@

maven 的命令如下

-h,--help                              Display help information
-am,--also-make                        构建指定模块,同时构建指定模块依赖的其他模块;
-amd,--also-make-dependents            构建指定模块,同时构建依赖于指定模块的其他模块;
-B,--batch-mode                        以批处理(batch)模式运行;
-C,--strict-checksums                  检查不通过,则构建失败;(严格检查)
-c,--lax-checksums                     检查不通过,则警告;(宽松检查)
-D,--define <arg>                      Define a system property
-e,--errors                            显示详细错误信息
-emp,--encrypt-master-password <arg>   Encrypt master security password
-ep,--encrypt-password <arg>           Encrypt server password
-f,--file <arg>                        使用指定的POM文件替换当前POM文件
-fae,--fail-at-end                     最后失败模式:Maven会在构建最后失败(停止)。如果Maven refactor中一个失败了,Maven会继续构建其它项目,并在构建最后报告失败。
-ff,--fail-fast                        最快失败模式: 多模块构建时,遇到第一个失败的构建时停止。
-fn,--fail-never                       从不失败模式:Maven从来不会为一个失败停止,也不会报告失败。
-gs,--global-settings <arg>            替换全局级别settings.xml文件(Alternate path for the global settings file)
-l,--log-file <arg>                    指定输出日志文件
-N,--non-recursive                     仅构建当前模块,而不构建子模块(即关闭Reactor功能)。
-nsu,--no-snapshot-updates             强制不更新SNAPSHOT(Suppress SNAPSHOT updates)
-U,--update-snapshots                  强制更新releases、snapshots类型的插件或依赖库(否则maven一天只会更新一次snapshot依赖)
-o,--offline                           运行offline模式,不联网进行依赖更新
-P,--activate-profiles <arg>           激活指定的profile文件列表(用逗号[,]隔开)
-pl,--projects <arg>                   手动选择需要构建的项目,项目间以逗号分隔;A project can be specified by [groupId]:artifactId or by its relative path.
-q,--quiet                             安静模式,只输出ERROR
-rf,--resume-from <arg>                从指定的项目(或模块)开始继续构建
-s,--settings <arg>                    替换用户级别settings.xml文件(Alternate path for the user settings file)
-T,--threads <arg>                     Thread count, for instance 2.0C where C is core multiplied
-t,--toolchains <arg>                  Alternate path for the user toolchains file
-V,--show-version                      Display version information WITHOUT stopping build
-v,--version                           Display version information
-X,--debug                             输出详细信息,debug模式。

打包不同环境需要用到下面的命令 :
这时候打包beta环境的命令就是

mvn clean package -DskipTests -P beta
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值