简体   繁体   English

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

[英]Maven dependencies from internal and central repository

I have an internal Nexus repository in Maven where some plugins are deployed. 我在Maven中有一个内部Nexus存储库,其中部署了一些插件。 There are some dependency jar file that are not present in the nexus repository while some are there. 有些依赖jar文件在nexus存储库中不存在,而有些则存在。 Is it possible to configure maven to search for the dependency jar files in internal repository and if not present search in the maven central repository. 是否可以将maven配置为在内部存储库中搜索依赖jar文件,如果不存在则在maven中央存储库中搜索。

Update 更新

Made the similar configuration as in answer of JimHawkins. 做出与JimHawkins的回答类似的配置。 But still I guess its looking only in the nexus internal repositories for the dependencies. 但我仍然认为它只关注依赖关系的nexus内部存储库。 Here are some of the debus messges it prints: 以下是它打印的一些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

If you modify your personal maven settings.xml (located in <HOME>/.m2 ) like shown below, maven searches your Nexus for dependencies, instead of looking in maven central rpository. 如果你修改你的个人maven settings.xml (位于<HOME>/.m2 /。m2),如下所示,maven会搜索你的Nexus的依赖项,而不是查看maven中央存储库。 If maven doesn't find them in Nexus, Nexus will download them from the maven central repository and than provide it to maven. 如果maven在Nexus中找不到它们, Nexus将从 maven中央存储库下载它们 ,而不是将其提供给maven。

Every dependency is also stored in your local maven repository on your workstation, after maven fetched it from Nexus 在从Nexus获取它之后,每个依赖项也存储在工作站上的本地maven存储库中

You can tell Nexus to search for new artifacts not only in maven central repository, but also in other public repos (such as JBoss public repository). 您可以告诉Nexus不仅在maven中央存储库中搜索新工件,还在其他公共存储库(例如JBoss公共存储库)中搜索新工件。

See also: Maven configuration 另请参见: Maven配置
Use these settings in settings.xml : settings.xml使用这些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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM