来自内部和中央存储库的Maven依赖项

来自内部和中央存储库的Maven依赖项,maven,dependencies,Maven,Dependencies,我在Maven中有一个内部Nexus存储库,其中部署了一些插件。有一些依赖项jar文件不在nexus存储库中,而有些则在那里。是否可以将maven配置为在内部存储库中搜索依赖项jar文件,如果不存在,则在maven中央存储库中搜索 更新 做出了与JimHawkins回答中类似的配置。但我仍然认为它只在nexus内部存储库中查找依赖项。以下是它打印的一些debus Messes: [DEBUG] Using mirror Nexus (<internal-repo>) for cent

我在Maven中有一个内部Nexus存储库,其中部署了一些插件。有一些依赖项jar文件不在nexus存储库中,而有些则在那里。是否可以将maven配置为在内部存储库中搜索依赖项jar文件,如果不存在,则在maven中央存储库中搜索

更新


做出了与JimHawkins回答中类似的配置。但我仍然认为它只在nexus内部存储库中查找依赖项。以下是它打印的一些debus Messes:

[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
[DEBUG]为central(repo1.maven.org/maven2)使用镜像Nexus()。
[调试]为Nexus(my.repository.com/repo/path)使用镜像Nexus()
[错误]无法解决的生成扩展:插件或其依赖项之一
无法解决:在中找不到org.co dehaus.plexus:plexus utils:jar:1.1
已缓存在本地存储库中

如果您修改您的个人maven
设置.xml
(位于
/.m2
)如下图所示,maven将搜索您的Nexus以查找依赖项,而不是查找maven central位置。如果maven没有在Nexus中找到它们,Nexus将从maven中央存储库下载它们,然后提供给maven

在maven从Nexus获取依赖项之后,每个依赖项也存储在工作站上的本地maven存储库中

您可以告诉Nexus不仅在maven central repository中搜索新工件,还可以在其他公共repo(例如JBoss公共repository)中搜索新工件

另请参见:
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>

关系
*
http://your.internal-nexus.com/content/groups/public
关系
真的
中心的
http://central
真的
真的
中心的
http://central
真的
真的
关系

这是默认的Maven行为“…内部Nexus存储库…”我假设,这是一个Nexus存储库,位于LAN/intranet中的服务器上。对吗?@michaldo-你必须明确地告诉maven去看nexus。查看我的回答是的,这是内部intranet存储请提供您的
pom.xml
settings.xml
中的匿名代码片段。检查运行Nexus的服务器是否可以访问internet。您是否配置了正确的代理设置?进行了类似的配置。但我仍然认为它只在nexus内部存储库中查找依赖项。下面是它使用镜像Nexus()为central()打印的一些debus消息:[DEBUG]。[调试]为Nexus()使用镜像Nexus()[错误]无法解决的生成扩展:插件或其依赖项之一无法解决:未能在本地缓存中找到org.co dehaus.plexus:plexus utils:jar:1.1 inrepository@ManikVij请在您的问题中提供更多信息,而不是评论。通过阅读评论来收集信息是一件痛苦的事情。我的maven构建在Jenkin CI管道上遇到了问题。依赖项人工制品是通过Nexus托管的代理和Nexus服务器上的本地缓存提取的,但插件依赖项一直向公共repo输出。上面的setting.xml给了我线索,我没有定义pluginRepositories。一切都安排好了,谢谢@JimHawkins