使用 com.googlecode.maven-download-plugin 下载多个工件

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

我想使用 download-maven-plugin

从 Maven 存储库下载多个工件

我可以很好地下载一个神器,但是当我添加第二个时它被忽略了:

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

认为 问题是 configuration 应该为每个 execution 指定并且 plugin 只声明一次,但是这个不编译:

<?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

或者,如果有另一种方法可以从 Maven 存储库下载到文件(具体来说,需要来自 settings.xml 的身份验证的私有存储库)- 例如使用 Wagon - 那也可以。

https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html 似乎是解决上述问题的更好方法。它将:

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

你可以 运行 mvn org.apache.maven.plugins:maven-dependency-plugin:copy-dependencies 。这将从您的 POM 中读取依赖项,正常使用 settings.xml,然后复制它们。默认是我认为 target 中的一个目录,但它是可配置的。