Section 16.4.1, “使用Nexus中央代理仓库”中的Maven配置能让你使用Nexus公共组,这个组从4个由Nexus管理的仓库解析构件,但是它不让你查阅public-snapshots组,该组包括了Apache和Codehaus的快照版。要配置Maven让它为发布版和插件都使用Nexus,你必须配置Maven,通过往你的Maven文件~/.m2/settings.xml中添加如下的镜像配置,使其查阅Nexus的组。
Example 16.2. 配置Maven使其为发布版和快照版使用Nexus
<settings>
<mirrors>
<mirror>
<!--This is used to direct the public snapshots repo in the
profile below over to a different nexus group -->
<id>nexus-public-snapshots</id>
<mirrorOf>public-snapshots</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
</mirror>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>development</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--this profile will allow snapshots to be searched when activated-->
<id>public-snapshots</id>
<repositories>
<repository>
<id>public-snapshots</id>
<url>http://public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public-snapshots</id>
<url>http://public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>development</activeProfile>
</activeProfiles>
</settings>在Example 16.2, “配置Maven使其为发布版和快照版使用Nexus”中我们定义了两个profile:development和public-snapshots。development
profile被配置成从central仓库下载构件,通过一个假的URL
http://central。public-snapshots被配置成从public-snapshot仓库下载构件,通过一个假的URL
http://public-snapshots。这些假的URL被同一settings.xml文件中的两个mirror配置重写。第一个镜像被配置成覆盖public-snapshots仓库,而使用public-snapshots
Nexus组。第二个镜像覆盖所有其它的仓库,而使用public
Nexus组。有了这些配置,所有的构建都会包含public
Nexus组,如果你想包含public-snapshots组,你必须添加public-snapshots这个Profile,通过在命令行使用如下的
-P 标志。
$ mvn -Ppublic-snapshots clean install

