我想使用 nexus 创建公司本地 maven 存储库。存储库不应从公共(public) Internet 下载任何内容,所需的一切都添加到 repo。开发人员的本地 maven 实例应从公司 nexus 下载所需的库和工具。我已经设法通过在 settings.xml 中使用这样的镜像来做到这一点:
<mirror>
<id>company-repository</id>
<name>Company releases repository</name>
<url>http://nexus.company.com/nexus/content/repositories/releases</url>
<mirrorOf>*</mirrorOf>
</mirror>
这个解决方案的问题是我只能指向发布存储库,我还想包括第三方和快照存储库来搜索。有谁知道应该怎么做?镜像标签只需要一个 url。
我也尝试过像这样定义默认配置文件:
<profile>
<id>defaultProfile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>company-thirdparty-repo</id>
<url>http://nexus.company.com//nexus/content/repositories/thirdparty</url>
<releases>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>company-releases-repo</id>
<url>http://nexus.company.com/nexus/content/repositories/releases</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://nexus.company.com/nexus/content/repositories/central</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
该解决方案的问题在于,如果 Maven 从这些存储库中找不到某些东西,它仍然会从 repo.maven.apache.org 下载它。我将不胜感激。谢谢!
最佳答案
您可以使用两者的组合:
为远程公共(public) repo 的代理创建一个存储库组(假设您将其称为 public)。使用它来镜像 Maven 的唯一默认存储库,即“中央”
对于其他存储库,只需将其添加为存储库/插件存储库
settings.xml 如下所示:
<settings>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://your/nexus/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<!-- for you to override settings of central -->
<id>central</id>
<url>http://a.fake.host</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>anotherRepo</id>
<url>http://your/nexus/groups/anotherRepo</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<!-- for you to override settings of central -->
<id>central</id>
<url>http://a.fake.host</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>anotherRepo</id>
<url>http://your/nexus/groups/anotherRepo</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
关于maven - 如何仅使用公司本地关系存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12257633/