你可以把profiles定义在4个地方:
%M2_HOME%/conf/tings.xml这是针对该部电脑所有userprofiles是global profiles它会影响所有maven project build
<your -home-directory>/.m2/tings.xml这是针对per userprofiles是user级profiles它会影响当前user所有maven project build
定义在pom.xml文件里面这是仅针对该projectprofiles是project级profiles
profiles.xml它和pom.xml在同个目录下也是project级profiles使用profiles.xml目是希望把profiles设置从pom.xml里抽离出来设置
定义在这4个地方profiles中涉及范围越窄profiles会覆盖范围越宽profiles即:定义在pom.xml里profiles会覆盖profiles.xmlprofiles.xml会覆盖<your -home-directory>/.m2/tings.xml<your -home-directory>/.m2/tings.xml会覆盖%M2_HOME%/conf/tings.xml
不过请注意:设置在pom.xml里profiles是最最推荐pom.xml会被deploy到repository里所以pom.xml里profiles才会available for subsequent builds originating from the repository or as transitive dependencies而tings.xml和profiles.xml里定义profiles不会被deploy到repository则有诸多限制因此只有下面几个profiles能够在tings.xml和profiles.xml里定义:
repositories
pluginRepositories
properties
其他类型profiles必须在pom.xml里定义(上面3个profiles也可以在pom.xml里定义)
Pom.xml能够定义profiles包括:
<repositories>
<pluginRepositories>
<dependencies>
<plugins>
<properties> (not actually available in the POM, but used behind the scenes)
<modules>
<reporting>
<dependencyManagement>
<distributionManagement>
a sub of the <build> element, which consists of:
<defaultGoal>
<resources>
<testResources>
<finalName>
激活Profiles
激活profiles有下列几种方式:
Explicitly
Through Maven tings
Based _disibledevent=dev
则输出是:
The following profiles are active:
- appserverConfig-dev (source: pom)
如果有个profile定义在tings.xml里并使用<activeProfile>激活那么输入命令:
mvn help:active-profiles
则输出是:
The following profiles are active:
- appserverConfig (source: tings.xml)
如果输入命令:
mvn help:active-profiles -P appserverConfig-dev
那么输出是:
The following profiles are active:
- appserverConfig-dev (source: pom)
- appserverConfig (source: tings.xml)
最新评论