Maven configuring setting XML details -- profiles, activation

Chen Bucheng I 2022-06-24 07:44:16 阅读数:647

mavenconfiguringsettingxmldetails

Profiles

effect : Adjust the list of build configurations based on the environment parameters . settings.xml Medium profile The element is pom.xml in profile The cut version of the element . It contains id、activation、repositories、pluginRepositories and properties Elements . there profile The element only contains these five sub elements because it only cares about building the system as a whole ( That's exactly what it is. settings.xml Role orientation of documents ), Instead of setting up a separate project object model . If one settings.xml Medium profile To be activated , Its value will override any other definition in pom.xml With the same id Of profile.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<profiles>
<profile>
<!-- profile Unique identification of -->
<id>test</id>
<!-- Automatic triggering profile The conditional logic of -->
<activation />
<!-- Extended attribute list -->
<properties />
<!-- Remote warehouse list -->
<repositories />
<!-- Plug in repository list -->
<pluginRepositories />
</profile>
</profiles>
...
</settings>

Activation

effect : Automatic triggering profile The conditional logic of . Such as pom.xml Medium profile equally ,profile It can automatically use certain values in certain environments ; These environments pass through activation Element designation . activation The element is not activated profile The only way .settings.xml In the document activeProfile Elements can contain profile Of id.profile It can also be done on the command line , Use -P Tag and comma separated list to explicitly activate ( Such as ,-P test)

<activation>
<!--profile Whether the default activation of the logo -->
<activeByDefault>false</activeByDefault>
<!-- When it matches jdk Detected ,profile To be activated . for example ,1.4 Activate JDK1.4,1.4.0_2, and !1.4 Activating all versions is not to 1.4 At the beginning JDK. -->
<jdk>1.5</jdk>
<!-- When a matching operating system property is detected ,profile To be activated .os Element can define some operating system related properties . -->
<os>
<!-- Activate profile The name of the operating system -->
<name>Windows XP</name>
<!-- Activate profile The operating system family of ( Such as 'windows') -->
<family>Windows</family>
<!-- Activate profile The operating system architecture of -->
<arch>x86</arch>
<!-- Activate profile The operating system version of -->
<version>5.1.2600</version>
</os>
<!-- If Maven An attribute was detected ( Its value can be in POM Pass through ${name} quote ), It has a corresponding name = value ,Profile Will be activated . If the value field is empty , Then the existence of the attribute name field will activate profile, Otherwise, match the property value fields in case sensitive way -->
<property>
<!-- Activate profile The name of the property of -->
<name>mavenVersion</name>
<!-- Activate profile The value of the property -->
<value>2.0.3</value>
</property>
<!-- Provide a filename , Activate... By detecting whether the file exists or does not exist profile.missing Check if the file exists , Activate if not present profile. On the other hand ,exists It will check if the file exists , Activate... If present profile. -->
<file>
<!-- If the specified file exists , Then activate profile. -->
<exists>${basedir}/file2.properties</exists>
<!-- If the specified file does not exist , Then activate profile. -->
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
copyright:author[Chen Bucheng I],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/175/20210628191923973g.html