|
nexus中的倉庫列表

第一種方式:

<repositories>
<repository>
<id>nexus</id>
<name>nexus Repository</name>
<url>http://localhost:8081/nexus/content/repositories/central/</url>
</repository>
</repositories>
這種方式,Maven僅僅只會在nexus中的central中央工廠進行下載,而我們希望我們開發(fā)的releases、snapshots工廠都能下載

而這種方式會增加配置的復(fù)雜度,并且增加了配置文件的冗余,而沒增加一個都會去添加,這種方式不推薦使用
第二種方式:
為解決第一種方式,在nexus中提供了另外一種方式倉庫為:Public Repositories 類型為group Repository Path為:http://localhost:8081/nexus/content/groups/public/
的方式

在pom.xml中我們只需要將url地址更改成它的地址即可,用了這個工廠就相當于用了Releases、Snapshots、3rd party 、Central這幾個工廠
<repositories>
<repository>
<id>nexus</id>
<name>nexus Repository</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
設(shè)置了之后,當我們有新的依賴,它就回去nexus中的倉庫中去下載

第二種方式,當還一個模塊的時候還的配置,這樣就不太方便,在企業(yè)開發(fā)中,我們需要設(shè)置一個共有的,因此第三中方式就來了
第三種方式
將自己設(shè)置的工廠中的settings.xml進行配置

<profiles>
<profile>
<id>nexusRepository</id>
<repositories>
<repository>
<id>nexus</id>
<name>nexus is Repository</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<!-- 默認就是true -->
<releases>
<enabled>true</enabled>
</releases>
<!-- 默認是是false,需手動打開 設(shè)置為true -->
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!-- 這里必須激活profile 才能生效 -->
<activeProfiles>
<activeProfile>nexusRepository</activeProfile>
</activeProfiles>
這樣默認也是從nexus repository下載
第三種方式在nexus服務(wù)器停止的了,maven有會從maven的中央工廠mvnrepository進行下載,這是因為,Maven項目首先回去nexus中去找,當它發(fā)現(xiàn)nexus服務(wù)停止這個時候它就回去找Maven的工廠
在Maven的安裝包中的lib中的maven-model-builder-3.3.9.jar中的pom.xml,起配置如下
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven./maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
問題就是當我們發(fā)現(xiàn)Nexus服務(wù)停止了就不能下載,而只能從Nexus中下載,不允許去Maven中下載這就需要第四種方式
第四種方式:配置鏡像

配置如下
<mirrors>
<mirror>
<id>mirrorNexusId</id>
<!-- *號代表所有工廠鏡像 ,當Maven進來之后,不管什么工廠都回去找URL的地址去下載 -->
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<!-- 這里的工廠配置,是Maven中的,起snapshots是false,我們可以通過這種方式將其激活,就可以訪問中央工廠中snapshots -->
<profiles>
<profile>
<id>nexusRepository</id>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven./maven2</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<!-- 這里必須激活profile 才能生效 -->
<activeProfiles>
<activeProfile>nexusRepository</activeProfile>
</activeProfiles>
第四種方式就是我們推薦的一種方式
|