Skip to content
Advertisement

Download multiple artifacts using com.googlecode.maven-download-plugin

I’d like to download several artifacts from a Maven repository using download-maven-plugin

I can download one artifact fine, but when I add a second it is ignored:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.me</groupId>
    <artifactId>libdownloader</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>com.googlecode.maven-download-plugin</groupId>
                <artifactId>download-maven-plugin</artifactId>
                <version>1.6.8</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <id>download-maven-plugin-lang3</id>
                        <goals>
                            <goal>artifact</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                    <version>3.12.0</version>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.googlecode.maven-download-plugin</groupId>
                <artifactId>download-maven-plugin</artifactId>
                <version>1.6.8</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <id>download-maven-plugin-guava</id>
                        <goals>
                            <goal>artifact</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                    <version>31.1-jre</version>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

I think the problem is that the configuration should be specified for each execution and the plugin declared only once, but this doesn’t compile:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.me</groupId>
    <artifactId>libdownloader</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>com.googlecode.maven-download-plugin</groupId>
                <artifactId>download-maven-plugin</artifactId>
                <version>1.6.8</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <id>download-maven-plugin-lang3</id>
                        <goals>
                            <goal>artifact</goal>
                        </goals>
                        <configuration>
                            <groupId>org.apache.commons</groupId>
                            <artifactId>commons-lang3</artifactId>
                            <version>3.12.0</version>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>generate-sources</phase>
                        <id>download-maven-plugin-guava</id>
                        <goals>
                            <goal>artifact</goal>
                        </goals>
                        <configuration>
                            <groupId>com.google.guava</groupId>
                            <artifactId>guava</artifactId>
                            <version>31.1-jre</version>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Failed to execute goal com.googlecode.maven-download-plugin:download-maven-plugin:1.6.8:artifact (default-cli) on project libdownloader: The parameters 'groupId', 'artifactId', 'version' for goal com.googlecode.maven-download-plugin:download-maven-plugin:1.6.8:artifact are missing or invalid

Alternatively, if there’s another way to download from a Maven repository to a file (specifically, a private repository that requires authentication from the settings.xml) – e.g. using Wagon – then that could work too.

Advertisement

Answer

https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html seems like a better solution for the stated problem. It will:

Goal that copies the project dependencies from the repository to a defined location.

You can run mvn org.apache.maven.plugins:maven-dependency-plugin:copy-dependencies . This will read the dependencies from your POM, use settings.xml as normal, and copy them. The default is a directory in I think target but it is configurable.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement