maven-dependency-plugin:解包错误

maven-dependency-plugin:unpack Error

我正在尝试从依赖 jar 文件中提取一些 .exe 文件并将它们放在 ${project.build.directory}/类/ 下。

但是当我执行时:

mvn clean compile dependency:unpack

我得到:

无法执行目标 org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack (default-cli) on project simple: 需要 artifact 或 artifactItems -> [Help 1

我已验证依赖项在我的本地存储库中可用。

在我下面的示例 pom 中,我使用了 junit 作为示例,但无论我列出哪个依赖项,我都会得到相同的错误。

pom.xml:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.10</version>
                  <type>jar</type>
                  <overWrite>false</overWrite>
  <outputDirectory>${project.build.directory}/classes/externaltools</outputDirectory>                   
                  <includes>**/*.txt</includes>
                </artifactItem>
              </artifactItems>   
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

问题是因为您不能同时使用 mvn clean compile dependency:unpack<executions> 标签。

在页面底部的文档 Maven Depdendency Plugin 中,您可以阅读:

If you intend to configure this mojo for execution on the command line using: mvn dependency:unpack you must not put the configuration inside the executions tag. Your configuration should look like this:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>[ groupId ]</groupId>
              <artifactId>[ artifactId ]</artifactId>
              <version>[ version ]</version>
              <type>[ packaging ]</type>
              <classifier> [classifier - optional] </classifier>
              <overWrite>[ true or false ]</overWrite>
              <outputDirectory>[ output directory ]</outputDirectory>
              <destFileName>[ filename ]</destFileName>
              <includes>[ comma separated list of file filters ]</includes>
              <excludes>[ comma separated list of file filters ]</excludes>
            </artifactItem>
          </artifactItems>
          <!-- other configurations here -->
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

我已经尝试删除 <execution> 标签并且效果很好!