如果在 settings.xml 中配置了镜像,则忽略项目存储库
Project repository is ignored if mirrors are configured in the settings.xml
我已经使用本指南创建了一个项目存储库:https://devcenter.heroku.com/articles/local-maven-dependencies
如果我注释掉 .m2 文件夹中 settings.xml
文件中的 mirrors
定义,这会很好用。
如果定义了镜像,则不考虑项目存储库。我是否也必须将它添加为镜像?如果这可以在 pom.xml
.
中以某种方式处理,那就太好了
pom.xml
<repositories>
<repository>
<id>repo</id>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
Settings.xml
<mirrors>
<mirror>
<id>de.companyname.repository.release</id>
<mirrorOf>de.companyname.repository</mirrorOf>
<url>https://repository.companyname.de/content/repositories/releases</url>
</mirror>
<mirror>
<id>de.companyname.repository</id>
<mirrorOf>de.companyname.repository</mirrorOf>
<url>https://repository.companyname.de/content/repositories/snapshots</url>
</mirror>
<mirror>
<id>nexus-else</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>central-snapshots</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public-snapshots</url>
</mirror>
</mirrors>
这是正常的,实际上是 mirrors. They are used in order to have Maven download dependencies from another location that the one defined in <repository>
element. More info on how it does that in this related answer 的用例。
在你的例子中,你有这个镜像配置:
<mirror>
<id>nexus-else</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
这意味着此 <mirror>
将镜像 *
,即所有存储库。所以你的 repo
声明在你的 POM 中没有被考虑在内,因为这个镜像被配置为镜像它。因此,Maven 在 file://${project.basedir}/repo
发出的每个请求实际上都被重定向到您的镜像 URL。您在这里有两个解决方案:
不要告诉 nexus-else
镜像基于本地文件的存储库。你可以用
<mirror>
<id>nexus-else</id>
<mirrorOf>external:*</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
external:*
matches all repositories except those using localhost or file based repositories. This is used in conjunction with a repository manager when you want to exclude redirecting repositories that are defined for Integration Testing.
由于您的 repo
声明是指向本地主机的文件存储库,因此 nexus-else
不会对其进行镜像。这也确保您将来添加的本地主机上任何其他基于文件的存储库也不会被镜像。
从镜像配置中排除 repo
:
<mirror>
<id>nexus-else</id>
<mirrorOf>*,!repo</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
*,!repo1
= everything except repo1
此解决方案可能比上面的解决方案更脆弱,因为您需要对存储库的 ID 进行硬编码。
我已经使用本指南创建了一个项目存储库:https://devcenter.heroku.com/articles/local-maven-dependencies
如果我注释掉 .m2 文件夹中 settings.xml
文件中的 mirrors
定义,这会很好用。
如果定义了镜像,则不考虑项目存储库。我是否也必须将它添加为镜像?如果这可以在 pom.xml
.
pom.xml
<repositories>
<repository>
<id>repo</id>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
Settings.xml
<mirrors>
<mirror>
<id>de.companyname.repository.release</id>
<mirrorOf>de.companyname.repository</mirrorOf>
<url>https://repository.companyname.de/content/repositories/releases</url>
</mirror>
<mirror>
<id>de.companyname.repository</id>
<mirrorOf>de.companyname.repository</mirrorOf>
<url>https://repository.companyname.de/content/repositories/snapshots</url>
</mirror>
<mirror>
<id>nexus-else</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>central-snapshots</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public-snapshots</url>
</mirror>
</mirrors>
这是正常的,实际上是 mirrors. They are used in order to have Maven download dependencies from another location that the one defined in <repository>
element. More info on how it does that in this related answer 的用例。
在你的例子中,你有这个镜像配置:
<mirror>
<id>nexus-else</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus.companyname.de:8081/nexus/content/groups/public</url>
</mirror>
这意味着此 <mirror>
将镜像 *
,即所有存储库。所以你的 repo
声明在你的 POM 中没有被考虑在内,因为这个镜像被配置为镜像它。因此,Maven 在 file://${project.basedir}/repo
发出的每个请求实际上都被重定向到您的镜像 URL。您在这里有两个解决方案:
不要告诉
nexus-else
镜像基于本地文件的存储库。你可以用<mirror> <id>nexus-else</id> <mirrorOf>external:*</mirrorOf> <url>http://nexus.companyname.de:8081/nexus/content/groups/public</url> </mirror>
external:*
matches all repositories except those using localhost or file based repositories. This is used in conjunction with a repository manager when you want to exclude redirecting repositories that are defined for Integration Testing.由于您的
repo
声明是指向本地主机的文件存储库,因此nexus-else
不会对其进行镜像。这也确保您将来添加的本地主机上任何其他基于文件的存储库也不会被镜像。从镜像配置中排除
repo
:<mirror> <id>nexus-else</id> <mirrorOf>*,!repo</mirrorOf> <url>http://nexus.companyname.de:8081/nexus/content/groups/public</url> </mirror>
*,!repo1
= everything except repo1此解决方案可能比上面的解决方案更脆弱,因为您需要对存储库的 ID 进行硬编码。