From: http://www.sonatype.com/books/maven-book/reference_zh/ch11s02.html
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook</groupId>
<artifactId>simple</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>production</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>false</debug>
<optimize>true</optimize>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
本例中,我们添加了一个名为production
的profile,它覆盖了Maven Compiler插件的默认配置,现在仔细看一下这个profile的语法。
|
pom.xml 中的profiles 元素,它包含了一个或者多个profile 元素。由于profile覆盖了pom.xml 中的默认设置,profiles 通常是pom.xml 中的最后一个元素。
|
|
每个profile必须要有一个id 元素。这个id 元素包含的名字将在命令行调用profile时被用到。我们可以通过传给Maven一个-P<profile_id>参数来调用profile。
|
|
一个profile 元素可以包含很多其它元素,只要这些元素可以出现在POM XML文档的project 元素下面。本例中,我们覆盖了Compiler插件的行为,因此必须覆盖插件配置,该配置通常位于一个build 和一个plugins 元素下面。
|
|
我们覆盖了Maven Compiler插件的配置。确保通过production profile产生的字节码不会包含调试信息,并且字节码会被编译器优化。
|
要使用production
profile来运行mvn install,你需要在命令行传入-Pproduction参数。要验证production
profile覆盖了默认的Compiler插件配置,可以像这样以开启调试输出(-X) 的方式运行Maven。
~/examples/profile $ mvn clean install -Pproduction -X
... (omitting debugging output) ...
[DEBUG] Configuring mojo 'o.a.m.plugins:maven-compiler-plugin:2.0.2:testCompile'
[DEBUG] (f) basedir = ~\examples\profile
[DEBUG] (f) buildDirectory = ~\examples\profile\target
...
[DEBUG] (f) compilerId = javac
[DEBUG] (f) debug = false
[DEBUG] (f) failOnError = true
[DEBUG] (f) fork = false
[DEBUG] (f) optimize = true
[DEBUG] (f) outputDirectory = \
~\svnw\sonatype\examples\profile\target\test-classes
[DEBUG] (f) outputFileName = simple-1.0-SNAPSHOT
[DEBUG] (f) showDeprecation = false
[DEBUG] (f) showWarnings = false
[DEBUG] (f) staleMillis = 0
[DEBUG] (f) verbose = false
[DEBUG] -- end configuration --
... (omitting debugging output) ...
Maven的调试输出体现了production profile下Compiler插件的配置。可以看到,debug
被设置成false,optimize
设置成true。
Example 11.2. Profile中允许出现的元素
<project>
<profiles>
<profile>
<build>
<defaultGoal>...</defaultGoal>
<finalName>...</finalName>
<resources>...</resources>
<testResources>...</testResources>
<plugins>...</plugins>
</build>
<reporting>...</reporting>
<modules>...</modules>
<dependencies>...</dependencies>
<dependencyManagement>...</dependencyManagement>
<distributionManagement>...</distributionManagement>
<repositories>...</repositories>
<pluginRepositories>...</pluginRepositories>
<properties>...</properties>
</profile>
</profiles>
</project>
分享到:
相关推荐
在maven中实现多环境的构建可移植性需要使用profile,通过不同的环境激活不同的profile来达到构建的可移植性。
通过Maven Profiles实现可移植性 11.2.1. 覆盖一个项目对象模型 11.3. 激活Profile 11.3.1. 激活配置 11.3.2. 通过属性缺失激活 11.4. 外部Profile 11.5. Settings Profile 11.5.1. 全局Settings ...
目 录 Maven Nexus配置 1.配置nexus 1 2.管理仓库 2 3. 管理组 2 4. 配置maven 3 5.部署构件至Nexus 4 6.Nexus监听端口 5 7.Maven Profiles 5
Task4Maven_TwoProfiles_Invoker 在这个项目中,我尝试调用 assembly:single 目标两次 - 使用“Profile1”和“Profile2”配置文件。 如果我只是调用 assembly:single goal with Profile1 或 Profile2 它工作正常。 ...
主要给大家介绍了关于maven profile自动切换环境参数的2种方法,文中通过示例代码将这两种方法介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
主要介绍了Maven管理SpringBoot Profile详解,具有一定参考价值,需要的朋友可以了解下。
profiles和maven assembly插件根据不同环境打包成tar.gz或者zip 将spring boot项目中的配置文件提取到外部config目录中 将spring boot项目中的启动jar包移动到boot目录中 将spring boot项目中的第三方依赖jar包移动...
使用maven Profile实现多环境构建,详细请参考 :http://blog.csdn.net/u011781521/article/details/77899467
当前案例中包含一整套的代码和word文档,非常适合新手... 主要是通过maven打包加载不同环境的properties文件 然后将对于的属性绑定到指定的实体对象中;然后通过调用接口可以看到加载不同环境控制台打印的内容是不一样的
Maven的profiles的使用例子
a NB project object model file, which is very userful to set up one maven project
maven-profiles
当前案例中包含一整套的代码和word文档,非常适合新手代码简单易懂; 主要是通过maven打包配合springboot application.properties文件配置实现通过打包来完成加载不同环境的配置内容;
Springboot Maven yaml 自动多环境打包工具 ...通过maven resources plugin把配置文件从src/main/resources/${profiles.active}拷贝到src/main/resources/ 然后打包 例如: mvn clean mvn package -P dev
Apache Maven是一个很流行的软件项目管理和理解工具,它能够被用来构建和管理任何基于java的项目,主要有以下几个目标: • 简化构建过程 • 提供统一的构建系统 • 提供高质量的项目信息 ...2.4、profiles配置
Learn how to use profiles, POM, parent POM, and modules Increase build-speed and decrease archive size Set, rationalize, and exclude transitive dependencies Optimize your POM and its dependencies ...
idea下test自动测试profiles配置
* [MNG-4918] - MavenProject#clone() doubles active profiles * [MNG-4919] - Plugin execution contributed by lifecycle mapping gets lost when same goal is bound multiple times * [MNG-4923] - ...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装