亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java?Maven?Settings配置參考教程

 更新時(shí)間:2023年09月11日 10:50:37   作者:授客  
這篇文章主要介紹了Java?Maven?Settings配置參考,本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

介紹

快速概覽

settings.xml文件中的 settings 元素包含用于定義以各種方式配置Maven執(zhí)行的值的元素,如pom.xml,但不應(yīng)綁定到任何特定項(xiàng)目或分發(fā)給受眾。這些值包括本地倉(cāng)庫(kù)位置、備用遠(yuǎn)程倉(cāng)庫(kù)服務(wù)器和身份驗(yàn)證信息。

settings.xml文件可能位于兩個(gè)地方:

  • Maven安裝:${maven.home}/conf/settings.xml

  • 用戶安裝:${user.home}/.m2/settings.xml

前者的 settings.xml也稱為全局設(shè)置,后者的 settings.xml稱為用戶設(shè)置。如果這兩個(gè)文件都存在,它們的內(nèi)容就會(huì)被合并,而用戶特定的 settings.xml占主導(dǎo)地位。

提示:如果您需要從頭開始創(chuàng)建特定于用戶的設(shè)置,最簡(jiǎn)單的方法是將全局設(shè)置從Maven安裝位置復(fù)制到${user.home}/.m2目錄中。Maven的默認(rèn) settings.xml是一個(gè)包含注釋和示例的模板,因此你可以快速調(diào)整它以滿足您的需求。

以下是settings下的頂級(jí)元素概述:

<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">
  <localRepository/>
  <interactiveMode/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors/>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

settings.xml的內(nèi)容可以使用以下表達(dá)式進(jìn)行插值(interpolated):

1.${user.home}和所有其他系統(tǒng)屬性(自Maven 3.0以來)

2.${env.HOME}等環(huán)境變量

請(qǐng)注意,在settings.xml 中的profiles中定義的屬性不能用于插值。

一個(gè)簡(jiǎn)單配置示例

<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <localRepository>D:\maven-repo</localRepository>
    <servers>
        <server>
            <username>testUser</username>
            <password>APBNwz5vH2BK2Et9ujKQsWQQ245</password>
            <id>central</id>
        </server>
        <server>
            <username>testUser</username>
            <password>APBNwz5vH2BK2Et9ujKQsWQQ245</password>
            <id>snapshots</id>
        </server>
    </servers>
    <mirrors>
        <mirror>
            <mirrorOf>*</mirrorOf>
            <name>maven</name>
            <url>https://artifactory.example.com/artifactory/maven</url>
            <id>maven</id>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <repositories>
                <repository>
                    <id>nexus-aliyun</id>
                    <name>nexus-aliyun</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>central</id>
                    <name>maven</name>
                    <url>https://artifactory.example.com/artifactory/maven</url>
                </repository>
                <repository>
                    <snapshots />
                    <id>snapshots</id>
                    <name>maven</name>
                    <url>https://artifactory.example.com/artifactory/maven</url>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>alimaven</id>
                    <name>aliyun maven</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                </pluginRepository>
                <pluginRepository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>central</id>
                    <name>maven</name>
                    <url>https://artifactory.example.com/artifactory/maven</url>
                </pluginRepository>
                <pluginRepository>
                    <snapshots />
                    <id>snapshots</id>
                    <name>maven</name>
                    <url>https://artifactory.example.com/artifactory/maven</url>
                </pluginRepository>
            </pluginRepositories>
            <id>artifactory</id>
        </profile>
        <profile>
            <id>jdk-1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>artifactory</activeProfile>
    </activeProfiles>
</settings>

Settings明細(xì)

簡(jiǎn)單值

頂級(jí)settings 元素的一半是簡(jiǎn)單值,表示一系列值,這些值描述了構(gòu)建系統(tǒng)中一直處于激活(active full-time)的元素

<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">
  <localRepository>${user.home}/.m2/repository</localRepository>
  <interactiveMode>true</interactiveMode>
  <offline>false</offline>
  ...
</settings>
  • localRepository: 該元素值是該構(gòu)建系統(tǒng)的本地倉(cāng)庫(kù)的路徑。默認(rèn)值為${user.home}/.m2/repository。該元素對(duì)于允許所有登錄用戶從公共本地倉(cāng)庫(kù)進(jìn)行構(gòu)建的主服務(wù)器構(gòu)建特別有用。

  • interactiveMode: 如果Maven應(yīng)該嘗試與用戶交互以獲取輸入則設(shè)置為true,否則為false。默認(rèn)為true

  • offline: 如果此生成系統(tǒng)應(yīng)在脫機(jī)模式下運(yùn)行則設(shè)置為true,否則為false。默認(rèn)為false。該元素對(duì)于由于網(wǎng)絡(luò)設(shè)置或安全原因而無法連接到遠(yuǎn)程倉(cāng)庫(kù)的服務(wù)器構(gòu)建非常有用。

插件組(Plugin Groups)

此元素包含一個(gè) pluginGroup 元素列表,每個(gè)元素都包含一個(gè)組ID。當(dāng)用到某個(gè)插件并且命令行中沒有提供該插件組件ID時(shí),會(huì)搜索該列表。此列表自動(dòng)包含org.apache.maven.pluginsorg.codehaus.mojo

<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">
  ...
  <pluginGroups>
    <pluginGroup>org.eclipse.jetty</pluginGroup>
  </pluginGroups>
  ...
</settings>

例如,跟進(jìn)上述給定的設(shè)置,Maven命令行可以使用截?cái)嗟拿顖?zhí)行org.eclipse.jetty:jetty-Maven plugin:run

mvn jetty:run

服務(wù)器(Servers)

由POM的repositions和distributionManagement元素定義的,用于下載和發(fā)布的倉(cāng)庫(kù)。但是,某些設(shè)置(如 username 和password )不應(yīng)與 pom.xml一起分發(fā)。此類信息應(yīng)存在于 settings.xml中的生成服務(wù)器上。

<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">
  ...
  <servers>
    <server>
      <id>server001</id>
      <username>my_login</username>
      <password>my_password</password>
      <privateKey>${user.home}/.ssh/id_dsa</privateKey>
      <passphrase>some_passphrase</passphrase>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
      <configuration></configuration>
    </server>
  </servers>
  ...
</settings>
  • id: 這是與Maven試圖連接的,與倉(cāng)庫(kù)/鏡像的 id 元素匹配的服務(wù)器(而不是要登錄的用戶)的ID。
  • usernamepassword: 這兩元素成對(duì)出現(xiàn),分別表示對(duì)此服務(wù)器進(jìn)行身份驗(yàn)證所需的登錄名和密碼。
  • privateKeypassphrase: 類似前兩個(gè)元素,這對(duì)元素指定私鑰(默認(rèn)為 ${user.home}/.ssh/id_dsa)和passphrase的路徑,如果必要的話。passphrase 和password元素將來可能會(huì)外部化,但目前它們必須在settings.xml文件中設(shè)置為純文本。
  • filePermissionsdirectoryPermissions: 在發(fā)布時(shí)創(chuàng)建倉(cāng)庫(kù)文件或目錄時(shí),需要使用的權(quán)限。每個(gè)的合法值是一個(gè)三位數(shù),對(duì)應(yīng)于*nix文件權(quán)限,例如664或775。

注意:如果使用私鑰登錄服務(wù)器,請(qǐng)確保省略<password> 元素。否則,該鍵將被忽略。

密碼加密

2.1.0+中添加了一項(xiàng)新功能-服務(wù)器密碼和passphrase加密。詳情請(qǐng)查閱https://maven.apache.org/guides/mini/guide-encryption.html

鏡像(Mirrors)

<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">
  ...
  <mirrors>
    <mirror>
      <id>planetmirror.com</id>
      <name>PlanetMirror Australia</name>
      <url>http://downloads.planetmirror.com/pub/maven2</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>
  • idname: 分別表示此鏡像的唯一標(biāo)識(shí)符和用戶友好的名稱。 id用于區(qū)分mirror元素,以及連接到鏡像時(shí),用于從servers 中選擇相應(yīng)的憑據(jù)。
  • url: 鏡像的基礎(chǔ)URL。構(gòu)建系統(tǒng)將使用此URL連接到倉(cāng)庫(kù),而不是原始倉(cāng)庫(kù)的URL。
  • mirrorOf: 設(shè)置要被鏡像的倉(cāng)庫(kù)id。例如,如需指向Mavencenter倉(cāng)庫(kù)(https://repo.maven.apache.org/maven2/)的鏡像,設(shè)置該元素值為center。更高級(jí)的映射,如repo1,repo2*,!inhouse也是可以的。該配置值一定與鏡像id不同。

有關(guān)鏡像的更深入介紹,請(qǐng)閱讀鏡像設(shè)置指南

鏡像設(shè)置指南

為倉(cāng)庫(kù)使用鏡像

擁有倉(cāng)庫(kù),你可以指定要從哪個(gè)位置下載某些工件,例如依賴項(xiàng)和maven插件。可以在項(xiàng)目?jī)?nèi)部聲明倉(cāng)庫(kù),這意味著,如果你有自己的自定義倉(cāng)庫(kù),那些共享你項(xiàng)目的可以很容易地獲得開箱即用的正確配置。但是,你可能希望在不更改項(xiàng)目文件的情況下為特定倉(cāng)庫(kù)使用備用鏡像。

使用鏡像的一些原因是:

  • 互聯(lián)網(wǎng)上有一個(gè)同步鏡像,地理位置更近、速度更快
  • 希望用自己的內(nèi)部倉(cāng)庫(kù)替換特定的倉(cāng)庫(kù),可以對(duì)其進(jìn)行更大的控制
  • 想運(yùn)行倉(cāng)庫(kù)管理器為鏡像提供本地緩存,而需要使用其URL

可以簡(jiǎn)單的把mirror理解為一個(gè)攔截器,攔截maven對(duì)遠(yuǎn)程repository的相關(guān)請(qǐng)求,然后把請(qǐng)求里的remote repository地址,重定向到mirror里配置的地址,如下

未配置鏡像前:

配置鏡像之后:

要為給定倉(cāng)庫(kù)配置鏡像,需在配置文件(${user.home}/.m2/settings.xml)中提供它,為新倉(cāng)庫(kù)指定自己的idurl,并指定mirrorOf設(shè)置,即被鏡像的倉(cāng)庫(kù)ID。例如,默認(rèn)情況下包含的Maven Central主倉(cāng)庫(kù)的ID為central,因此要使用不同的鏡像實(shí)例,需要配置以下內(nèi)容:

<settings>
  ...
  <mirrors>
    <mirror>
      <id>other-mirror</id>
      <name>Other Mirror Repository</name>
      <url>https://other-mirror.repo.other-company.com/maven2</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

注意,對(duì)于給定的倉(cāng)庫(kù),最多可以有一個(gè)鏡像。換句話說,不能將單個(gè)倉(cāng)庫(kù)映射到一組定義相同<mirrorOf>值的鏡像。Maven不會(huì)聚合鏡像,而是簡(jiǎn)單地選擇第一個(gè)匹配的鏡像。如果要提供多個(gè)倉(cāng)庫(kù)的組合視圖,請(qǐng)使用倉(cāng)庫(kù)管理器。

settings.xml述符文檔查閱https://maven.apache.org/ref/3.9.3/maven-settings/settings.html

:Maven的官方倉(cāng)庫(kù)位于https://repo.maven.apache.org/maven2由Sonatype公司托管,并通過CDN在全球范圍內(nèi)分發(fā)。

倉(cāng)庫(kù)Metadata中提供了已知鏡像的列表。這些鏡像可能沒有相同的內(nèi)容,我們不以任何方式支持它們。

使用單個(gè)倉(cāng)庫(kù)

可以通過讓Maven鏡像所有倉(cāng)庫(kù)請(qǐng)求來強(qiáng)制它使用單個(gè)倉(cāng)庫(kù)。倉(cāng)庫(kù)必須包含所有所需的工件,或者能夠?qū)⒄?qǐng)求代理到其他倉(cāng)庫(kù)。當(dāng)使用具有代理外部請(qǐng)求的Maven 倉(cāng)庫(kù)管理器的內(nèi)部公司倉(cāng)庫(kù)時(shí),此設(shè)置最有用。

為此,請(qǐng)將 mirrorOf設(shè)置為*

注意:此功能僅在Maven 2.0.5+中可用。

<settings>
  ...
  <mirrors>
    <mirror>
      <id>internal-repository</id>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://repo.mycompany.com/proxy</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

高級(jí)設(shè)置

單個(gè)鏡像可以處理多個(gè)倉(cāng)庫(kù)。這通常與倉(cāng)庫(kù)管理器結(jié)合使用,后者可以方便地集中配置鏡像背后的倉(cāng)庫(kù)列表。

語(yǔ)法:

  • *匹配所有倉(cāng)庫(kù)ID。
  • external:*匹配除使用localhost或基于文件的倉(cāng)庫(kù)以外的所有倉(cāng)庫(kù)。當(dāng)希望排除為集成測(cè)試定義的重定向倉(cāng)庫(kù)時(shí),使用此選項(xiàng)。
  • 從Maven 3.8.0開始, external:http:* 匹配使用localhost除外,所有使用HTTP的倉(cāng)庫(kù)
  • 可以使用逗號(hào)作為分隔符指定多個(gè)倉(cāng)庫(kù)
  • 感嘆號(hào)可以與上述通配符之一一起使用,以排除倉(cāng)庫(kù)id

注意不要在逗號(hào)分隔列表中的標(biāo)識(shí)符或通配符周圍包含額外的空格。例如,將<mirrorOf>設(shè)置為!repo1, *不會(huì)鏡像任何內(nèi)容,而!repo1,*將鏡像除repo1之外的所有內(nèi)容。

通配符在以逗號(hào)分隔的倉(cāng)庫(kù)標(biāo)識(shí)符列表中的位置并不重要,因?yàn)橥ㄅ浞麜?huì)推遲進(jìn)一步處理,并且顯式包含或排除會(huì)停止處理,從而否決任何通配符匹配(原文:The position of wildcards within a comma separated list of repository identifiers is not important as the wildcards defer to further processing and explicit includes or excludes stop the processing, overruling any wildcard match)。

當(dāng)您使用高級(jí)語(yǔ)法并配置多個(gè)鏡像時(shí),聲明順序很重要。當(dāng)Maven查找某個(gè)倉(cāng)庫(kù)的鏡像時(shí),它首先檢查<mirrorOf>與倉(cāng)庫(kù)標(biāo)識(shí)符完全匹配的鏡像。如果沒有找到直接匹配,Maven會(huì)根據(jù)上面的規(guī)則(如果有的話)選擇第一個(gè)匹配的鏡像聲明。因此,可以通過更改settings.xml中定義的順序來影響匹配順序

示例:

  • *=所有倉(cāng)庫(kù)

  • external:*=所有不在本地主機(jī)上且不基于文件的內(nèi)容。

  • repo,repo1 = repo 或者repo1

  • *,!repo1 = 除repo1的所有倉(cāng)庫(kù)

<settings>
  ...
  <mirrors>
    <mirror>
      <id>internal-repository</id>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://repo.mycompany.com/proxy</url>
      <mirrorOf>external:*,!foo</mirrorOf>
    </mirror>
    <mirror>
      <id>foo-repository</id>
      <name>Foo</name>
      <url>http://repo.mycompany.com/foo</url>
      <mirrorOf>foo</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

創(chuàng)建自己的鏡像

central倉(cāng)庫(kù)的大小正在穩(wěn)步增加。為了節(jié)省帶寬和你的時(shí)間,不允許鏡像整個(gè)central倉(cāng)庫(kù)(如果這樣做會(huì)被自動(dòng)禁止)相反,建議設(shè)置一個(gè)倉(cāng)庫(kù)管理器 作為代理。

代理(Proxies)

<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">
  ...
  <proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
    </proxy>
  </proxies>
  ...
</settings>
  • id: 此代理的唯一標(biāo)識(shí)符。這用于區(qū)分proxy 元素。

  • activetrue 如果此代理處于活動(dòng)狀態(tài),則為true 。這對(duì)于聲明一組代理很有用,但一次只能有一個(gè)代理處于活動(dòng)狀態(tài)。

  • protocolhostport: 代理的 protocol://host:port,分隔成單個(gè)元素

  • usernamepassword: 這些元素成對(duì)出現(xiàn),表示對(duì)此代理服務(wù)器進(jìn)行身份驗(yàn)證所需的登錄名和密碼

  • nonProxyHosts: 這是不應(yīng)使用代理的主機(jī)列表。列表的分隔符是代理服務(wù)器的預(yù)期類型;上面的例子是管道分隔的,逗號(hào)分隔也是常見的。

Profiles

settings.xml中的profile 元素是 pom.xml profile 元素的“裁剪”版本。它由activationrepositoriespluginRepositories 和 properties 元素組成。 profile元素只包括這四個(gè)元素,因?yàn)樗鼈冴P(guān)注的是整個(gè)構(gòu)建系統(tǒng)(即settings.xml文件的作用),而不是單個(gè)項(xiàng)目對(duì)象模型設(shè)置。

如果一個(gè)settings.xml中的profile被激活,它的值會(huì)覆蓋任何其它定義在pom.xmlprofiles.xml中帶有相同ID的profile。

Activation

Activations是配置文件的關(guān)鍵。與POM的profiles一樣,profile的力量來自于它僅在特定情況下修改某些值的能力;這些情況是通過<activation>元素指定的。

<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>
      <id>test</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <jdk>1.5</jdk>
        <os>
          <name>Windows XP</name>
          <family>Windows</family>
          <arch>x86</arch>
          <version>5.1.2600</version>
        </os>
        <property>
          <name>mavenVersion</name>
          <value>2.0.3</value>
        </property>
        <file>
          <exists>${basedir}/file2.properties</exists>
          <missing>${basedir}/file1.properties</missing>
        </file>
      </activation>
      ...
    </profile>
  </profiles>
  ...
</settings>

當(dāng)滿足所有指定的條件時(shí),將激活profile,但并非需要同時(shí)滿足所有條件。

  • jdkactivation在 jdk 元素中有一個(gè)內(nèi)置的、以Java為中心的檢查。如果在與給定版本前綴匹配的jdk版本號(hào)下運(yùn)行測(cè)試,這將激活profile。在上面的示例中,1.5.0_06將匹配給定前綴即1.5。也支持范圍。請(qǐng)參閱maven enforcer插件獲取有關(guān)支持范圍的更多詳細(xì)信息。

  • osos元素可以定義上面顯示的一些特定于操作系統(tǒng)的屬性。請(qǐng)參閱maven enforcer插件獲取有關(guān)操作系統(tǒng)值的更多詳細(xì)信息。

  • property:如果Maven檢測(cè)到相應(yīng)的name=value 對(duì)的屬性(一個(gè)可以在pom.xml中通過 ${name}間接引用的值),則 profile 將被激活。

  • file:最后,可通過給定文件名對(duì)應(yīng)文件的 existence 或者missing激活 profile

activation 元素并不是激活profile的唯一方式。 settings.xml文件的activeProfile 元素可能包含profile的id。它們也可以通過命令行,通過 -P 標(biāo)志后的逗號(hào)分隔列表(例如 -P test)顯式激活。

要查看哪個(gè)配置文件將在某個(gè)構(gòu)建中激活,請(qǐng)使用maven-help-plugin

mvn help:active-profiles

屬性(Properties)

Maven properties是值占位符,類似于Ant中的properties。通過使用表示法 ${X},可以在POM中的任何位置訪問它們的值,其中 X 是屬性。它們有五種不同的形式,都可以從settings.xml文件中訪問:

  • env.X: 在變量前面加上“env.”前綴,將返回shell的環(huán)境變量。例如,${env.PATH} 包含$path環(huán)境變量(在Windows中為%PATH%)。
  • project.x: POM中.分路徑包含相應(yīng)元素的值。例如:可通過 ${project.version}獲取1.0。
  • settings.xsettings.xml 中的.分路徑包含相應(yīng)元素的值。例如可通過${settings.offline}得到false 值。
  • Java 系統(tǒng)屬性: 所有屬性,可通過java.lang.System.getProperties() 獲取并可作為POM properties,比如 ${java.home}.
  • x: 在某個(gè)<properties />元素或者某個(gè)外部文件中設(shè)置, 其值可能被用作${someVar}
<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>
      ...
      <properties>
        <user.install>${user.home}/our-project</user.install>
      </properties>
      ...
    </profile>
  </profiles>
  ...
</settings>

如果profile被激活的話,可通過POM訪問屬性${user.install}

倉(cāng)庫(kù)(Repositories)

Repositories 是Maven用來填充構(gòu)建系統(tǒng)的本地倉(cāng)庫(kù)的遠(yuǎn)程項(xiàng)目集合。Maven將其稱為插件和依賴項(xiàng)的正是來自該本地倉(cāng)庫(kù)。不同的遠(yuǎn)程倉(cāng)庫(kù)可能包含不同的項(xiàng)目,profile激活的情況下,可以搜索它們以查找匹配的release或snapshot工件

<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>
      ...
      <repositories>
        <repository>
          <id>codehausSnapshots</id>
          <name>Codehaus Snapshots</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <url>http://snapshots.maven.codehaus.org/maven2</url>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>myPluginRepo</id>
          <name>My Plugins repo</name>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <url>https://maven-central-eu....com/maven2/</url>
        </pluginRepository>
      </pluginRepositories>
      ...
    </profile>
  </profiles>
  ...
</settings>
  • releasessnapshots: 這些是針對(duì)每種類型的工件,Release 或snapshot的策略。有了這兩個(gè)集合,POM就有能力在單個(gè)倉(cāng)庫(kù)中獨(dú)立于其他類型來更改每種類型的策略。例如,可能出于開發(fā)目的,可以決定只啟用snapshot下載。
  • enabledtrue or false ,以確定是否為相應(yīng)類型(releases or snapshots)啟用此倉(cāng)庫(kù)。
  • updatePolicy: 此元素指定嘗試進(jìn)行更新的頻率。Maven將本地POM的時(shí)間戳(存儲(chǔ)在倉(cāng)庫(kù)的Maven元數(shù)據(jù)文件中)與遠(yuǎn)程POM進(jìn)行比較。選項(xiàng)為: alwaysdaily (默認(rèn))、或者interval:X(其中X是以分鐘為單位的整數(shù))或never。
  • checksumPolicy: 當(dāng)Maven將文件發(fā)布到倉(cāng)庫(kù)時(shí),它還會(huì)發(fā)布相應(yīng)的校驗(yàn)和文件。關(guān)于丟失或不正確的校驗(yàn)和時(shí),可以選擇 ignorefail或 warn 。
  • layout: 在上面對(duì)倉(cāng)庫(kù)的描述中,有人提到它們都遵循一個(gè)通用的布局。這基本上是正確的。Maven2有一個(gè)默認(rèn)的倉(cāng)庫(kù)布局;然而,Maven1.x有一個(gè)不同的布局。使用此元素指定是default還是 legacy

插件倉(cāng)庫(kù)(Plugin Repositories)

倉(cāng)庫(kù)是兩種主要類型的工件的所在地。第一種是用作其他工件的依賴項(xiàng)的工件。這些是位于中心的大多數(shù)工件。另一種類型的工件是插件。Maven插件本身就是一種特殊類型的工件。正因?yàn)槿绱?,插件倉(cāng)庫(kù)可能會(huì)與其他倉(cāng)庫(kù)分離(盡管,我還沒有聽到這樣做的令人信服的論據(jù))。在任何情況下, pluginRepositories 元素塊的結(jié)構(gòu)都類似于 repositories 元素。 pluginRepository元素分別指定Maven可以在其中查找新插件的遠(yuǎn)程位置。

激活Profiles(Active Profiles)

<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">
  ...
  <activeProfiles>
    <activeProfile>env-test</activeProfile>
  </activeProfiles>
</settings>

settings.xml謎題的最后一塊是activeProfiles 元素。它包含一系列activeProfiles 元素,每個(gè)元素的值都有一個(gè) profile id。任何定義為activeProfileprofile id 都將處于活動(dòng)狀態(tài),而與任何環(huán)境設(shè)置無關(guān)。如果沒有找到匹配的profile,則什么也不會(huì)發(fā)生。例如,如果env-test為一個(gè)activeProfile,一個(gè)在具有相應(yīng)idpom.xml(或profile.xml)將處于活動(dòng)狀態(tài)。如果找不到這樣的profile,則執(zhí)行將照常進(jìn)行。

參考鏈接

https://maven.apache.org/settings.html

https://maven.apache.org/ref/3.9.3/maven-settings/settings.html

到此這篇關(guān)于Java Maven Settings配置參考的文章就介紹到這了,更多相關(guān)Java Maven Settings配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Fluent Mybatis零xml配置實(shí)現(xiàn)復(fù)雜嵌套查詢

    Fluent Mybatis零xml配置實(shí)現(xiàn)復(fù)雜嵌套查詢

    本文主要介紹了Fluent Mybatis零xml配置實(shí)現(xiàn)復(fù)雜嵌套查詢,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • springmvc+mybatis 做分頁(yè)sql 語(yǔ)句實(shí)例代碼

    springmvc+mybatis 做分頁(yè)sql 語(yǔ)句實(shí)例代碼

    本文通過一段實(shí)例代碼給大家介紹了springmvc+mybatis 做分頁(yè)sql 語(yǔ)句的方法,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2017-07-07
  • MyBatisPlus+SpringBoot實(shí)現(xiàn)樂觀鎖功能詳細(xì)流程

    MyBatisPlus+SpringBoot實(shí)現(xiàn)樂觀鎖功能詳細(xì)流程

    樂觀鎖是針對(duì)一些特定問題的解決方案,主要解決丟失更新問題,下面這篇文章主要給大家介紹了關(guān)于MyBatisPlus+SpringBoot實(shí)現(xiàn)樂觀鎖功能的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-03-03
  • 詳解mybatis通過mapper接口加載映射文件

    詳解mybatis通過mapper接口加載映射文件

    本篇文章主要介紹了mybatis通過mapper接口加載映射文件 ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • 詳解Java反射各種應(yīng)用

    詳解Java反射各種應(yīng)用

    Java除了給我們提供在編譯期得到類的各種信息之外,還通過反射讓我們可以在運(yùn)行期間得到類的各種信息。通過反射獲取類的信息,得到類的信息之后,就可以獲取很多相關(guān)內(nèi)容。下面跟著小編一起來看下吧
    2017-01-01
  • SWT(JFace)體驗(yàn)之模擬BorderLayout布局

    SWT(JFace)體驗(yàn)之模擬BorderLayout布局

    SWT(JFace)體驗(yàn)之模擬BorderLayout布局代碼。
    2009-06-06
  • 淺析Spring Security登錄驗(yàn)證流程源碼

    淺析Spring Security登錄驗(yàn)證流程源碼

    這篇文章主要介紹了Spring Security登錄驗(yàn)證流程源碼解析,本文結(jié)合源碼講解登錄驗(yàn)證流程,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-11-11
  • java 將數(shù)據(jù)加載到內(nèi)存中的操作

    java 將數(shù)據(jù)加載到內(nèi)存中的操作

    這篇文章主要介紹了java 將數(shù)據(jù)加載到內(nèi)存中的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • spring?boot集成smart-doc自動(dòng)生成接口文檔詳解

    spring?boot集成smart-doc自動(dòng)生成接口文檔詳解

    這篇文章主要介紹了spring?boot集成smart-doc自動(dòng)生成接口文檔詳解,smart-doc是一款同時(shí)支持java?restful?api和Apache?Dubbo?rpc接口文檔生成的工具,smart-doc顛覆了傳統(tǒng)類似swagger這種大量采用注解侵入來生成文檔的實(shí)現(xiàn)方法
    2022-09-09
  • java計(jì)算自冪數(shù)和水仙花數(shù)

    java計(jì)算自冪數(shù)和水仙花數(shù)

    對(duì)于一個(gè)正整數(shù)而言,長(zhǎng)度是n,如果它的各位上的數(shù)字的n次方之和正好等于它本身,那么我們稱這樣的數(shù)為自冪數(shù),下面使用JAVA實(shí)現(xiàn)這個(gè)方法
    2014-03-03

最新評(píng)論