nexus公司maven nexus maven配置
转载
有两种方式
第一种:最简单明了的方式
直接在你项目的pom.xml中添加如下
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Public Repositories</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
|
那么,maven会首先从你配置的公共仓库中取信息,取不到再去默认的仓库取
第二种: 配置稍复杂
为了使用Nexus,你将要配置Maven去检查Nexus而不是公共仓库。为此,你需要需该Maven的mirror setting,该配置文件在~/.m2/settings.xml也有可能是Maven目下路conf/settings.xml.首先,我们演示如何配置Maven查阅你的Nexus而不是Maven Central repository。然后我们重写central repository并验证Nexus是工作的。
配置Maven使用单个Nexus Group
如果你想更改Nexus用于内部开发,你应该配置一个包含了release版和snapshot的single nexus group。为此,你需要添加snapshot仓库到你的public group,并且在你的Maven的settings.xml中添加如下内容:
<settings>
<mirrors>
<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>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<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>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
|
在上面的配置信息中,我们定义了一个single group:nexus。 然后配置了repository以及pluginRepository并以id "central"命名,这个配置重写了super pom的同名的仓库。我们更改了仓库让其支持snapshots并且使用了伪造的URL替换了默认URL,这样nexus group能够包含release以及snapshot版的artifacts,并且maven可以使用它们。
为Missing Denpendence添加一个自定义的仓库
如果你曾经配置了maven settings.xml来列出nexus的public group里所有的仓库,你可能遇到你的项目无法在本地nexus取得artifacts信息。这很有可能是因为你尝试去构建在pom中定义的自定义仓库或者snapshotRepository。
首先登陆nexus,默认的用户名和密码是admin/admin123,按图示进行选择:
在弹出框中选择Proxy Repository,填写表单后保存即可。
第二种方式也是nexus官方文档的做法,但是我没有配置成功,总是报无法找到xxx, 因为赶工期,也就暂时搁置不研究了。
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。