简体   繁体   中英

Maven dependencies from internal and central repository

I have an internal Nexus repository in Maven where some plugins are deployed. There are some dependency jar file that are not present in the nexus repository while some are there. 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.

Update

Made the similar configuration as in answer of JimHawkins. But still I guess its looking only in the nexus internal repositories for the dependencies. Here are some of the debus messges it prints:

[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. If maven doesn't find them in Nexus, Nexus will download them from the maven central repository and than provide it to maven.

Every dependency is also stored in your local maven repository on your workstation, after maven fetched it from Nexus

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).

See also: Maven configuration
Use these settings in 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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