我在 Maven 中有一个内部 Nexus 存储库,其中部署了一些插件。有一些依赖项 jar 文件不存在于 Nexus 存储库中,而有些则存在。是否可以配置 maven 在内部存储库中搜索依赖项 jar 文件,如果不存在则在 maven 中央存储库中搜索。
更新
做了与 JimHawkins 的回答类似的配置。但我仍然猜想它只在 Nexus 内部存储库中查找依赖项。以下是它打印的一些 debus 消息:
[DEBUG] Using mirror Nexus (<internal-repo>) for central (repo1.maven.org/maven2).
[DEBUG] Using mirror Nexus (<internal-repo>) for Nexus (my.repository.com/repo/path)
[ERROR] Unresolveable build extension: Plugin <plugin-name> or one of its dependencies
could not be resolved: Failure to find org.co dehaus.plexus:plexus-utils:jar:1.1 in <internal-repo>
was cached in the local repository
最佳答案
如果修改你的个人maven settings.xml
(位于 <HOME>/.m2
)如下所示,maven 在 Nexus 中搜索依赖项,而不是在 maven 中央存储库中查找。如果 Maven 在 Nexus 中找不到它们,Nexus 将从 Maven 中央存储库下载它们,然后将其提供给 Maven。
maven 从 Nexus 获取后,每个依赖项也会存储在工作站上的本地 maven 存储库中
您可以告诉 Nexus 不仅在 Maven 中央存储库中搜索新 Artifact ,还可以在其他公共(public)存储库(例如 JBoss 公共(public)存储库)中搜索新 Artifact 。
另请参阅:Maven configuration
在 settings.xml
中使用这些设置:
<mirrors>
<!--
mirror | Specifies a repository mirror site to use instead of a
given repository. The repository that | this mirror serves has an ID
that matches the mirrorOf element of this mirror. IDs are used | for
inheritance and direct lookup purposes, and must be unique across
the set of mirrors. | <mirror> <id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this
Mirror.</name> <url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://your.internal-nexus.com/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<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>
<activeProfile>nexus</activeProfile>
</activeProfiles>
关于来自内部和中央存储库的 Maven 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39412794/