httpmavenftpmaven-wagon-plugin

Maven: how to setup my pom.xml so that it can fetch dependencies via HTTP and deploy module via FTP


I'm trying to setup the pom.xml for one of my projects. And I can't figure out how to make it fetch dependencies via HTTP, but deploy new artifacts via FTP.

Here's the situation. I have a multi-module project on which I am working collaboratively with some other people. I also happen to rent a cheap web server that could allow me to share release and snapshot versions of some of my modules via a maven repository.

I want deployment to the repository to be authenticated (so that only authorized people can write to it) and to be done via FTP.

On the other hand, I want everyone to be able to download the published version of the artifacts anonymously via HTTP.

So far, the only thing I found was to add the following section to my pom.xml

<distributionManagement>
    <snapshotRepository>
        <id>my.repo.snapshots</id>
        <name>My Repository - Snapshots</name>
        <url>${url}/snapshots</url>
    </snapshotRepository>
    <repository>
        <id>my.repo.releases</id>
        <name>My Repository - Releases</name>
        <url>${url}/releases</url>
    </repository>
</distributionManagement>

The problem with this setup is that it doesn't let me pick FTP for upload and HTTP for download.

Is there any way to configure my pom.xml to do that?


Solution

  • Turns out the solution was right under my nose. The repositories for deploying artifacts are indeed configured through <distributionManagement/>, but repositories for fetching artifacts are configured through the <repositories> element in the <profiles> section.

    My working pom.xml configuration now includes:

    <distributionManagement>
        <repository>
            <id>deploy.releases</id>
            <name>Repository - Releases</name>
            <url>ftp://ftp.domain.com/releases/</url>
        </repository>
        <snapshotRepository>
            <id>deploy.snapshots</id>
            <name>Repository - Snapshots</name>
            <url>ftp://ftp.domain.com/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    
    <profiles>
        <profile>
            <id>project.default</id>
    
            <activation>
                <property>
                    <name>!skipProjectDefaultProfile</name>
                </property>
            </activation>
    
            <repositories>
                <repository>
                    <id>repo.releases</id>
                    <url>http://maven.domain.com/releases/</url>
                </repository>
                <repository>
                    <id>repo.snapshots</id>
                    <url>http://maven.domain.com/snapshots/</url>
                </repository>
            </repositories>
        </profile>
    </profiles>
    

    on top of that, my settings.xml contains the authentication information for FTP

    <servers>
        <server>
            <id>deploy.releases</id>
            <username>user</username>
            <password>pass</password>
        </server>
        <server>
            <id>deploy.snapshots</id>
            <username>user</username>
            <password>pass</password>
        </server>
    </servers>