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

时间:2016-09-09 13:33:16

标签: maven dependencies

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

更新

采用与JimHawkins的回答类似的配置。但我仍然认为它只关注依赖关系的nexus内部存储库。以下是它打印的部分内容:

[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

1 个答案:

答案 0 :(得分:0)

如果你修改了你的个人专家settings.xml(位于<HOME>/.m2),如下所示,maven会在你的Nexus中搜索依赖关系,而不是查看maven中央知识库。如果maven在Nexus中找不到它们, Nexus会从maven中央存储库下载,而不是将其提供给maven。

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

您可以告诉Nexus不仅在maven中央存储库中搜索新工件,还在其他公共存储库(例如JBoss公共存储库)中搜索新工件。

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