Search code examples
mavenjenkinsarchiva

Build/Deploy third-party project in maven but upload to my snapshots repository


I build weekly a large third-party project (apache sling) in Jenkins. I've got jenkin's settings.xml set up to use my own archiva server to download all dependencies (using the mirror section).

However, I haven't figured out how to get the build to upload snapshots my own snapshots repository when doing a 'deploy'. It instead tries to upload the snapshots to an apache.org snapshots server and fails.

Is there a way to configure settings.xml to override the snapshots server in a similar way it's possible to override the repository? This has to be done without editing the project's pom.xml.

The reason I need to do this is because I need access to some of the snapshot versions as dependencies in another project, and I don't want to have to manually upload them all into archiva.

Here's my settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<localRepository>/Users/Shared/Jenkins/.m2/repository</localRepository>

<servers>
    <server>
        <id>astra.internal</id>
        <username>-deleted-</username>
        <password>-deleted-</password>
    </server>
    <server>
        <id>astra.snapshots</id>
        <username>-deleted-</username>
        <password>-deleted-</password>
    </server>
</servers>

<mirrors>
    <mirror>
        <id>central-proxy</id>
        <name>Local proxy of central repo</name>
        <url>http://-deleted-.com/repository/internal</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
    <mirror>
        <id>snapshots</id>
        <name>Local proxy of snapshots</name>
        <url>http://-deleted-.com/repository/internal</url>
        <mirrorOf>snapshots</mirrorOf>
    </mirror>
</mirrors>

<profiles>
    <profile>
        <id>Repository Proxy</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <!-- ******************************************************* -->
        <!-- repositories for jar artifacts -->
        <profile>
            <!-- ******************************************************* -->
            <repositories>
                <repository>
                    <id>astra.internal</id>
                    <url>http://-deleted-.com/repository/internal/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>

                <repository>
                    <id>astra.snapshots</id>
                    <url>http://-deleted-.com/repository/snapshots/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </profile>
    </profiles>
</settings>

Solution

  • You can overwrite the Distribution management section with command line parameters.

    mvn clean deploy -DaltDeploymentRepository=ui-snapshots::default::http://localhost:8081/artifactory/libs-snapshot-local/

    Have a look at the maven deploy plugin.

    Alternatively, you should be able to use the Jenkins post build step. There you need to specifically provide the Repo url anyway.