maven-dependency-plugin:解包错误

时间:2015-05-15 11:42:52

标签: maven-3 maven-dependency-plugin

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

但是当我执行时:

mvn clean compile dependency:unpack

我得到:

无法执行目标org.apache.maven.plugins:maven-dependency-plugin:2.10:解压缩(default-cli)项目简单:需要artifact或artifactItems - > [帮助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>

1 个答案:

答案 0 :(得分:9)

问题是由于您无法一起使用mvn clean compile dependency:unpack<executions>标记。

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

  

如果您打算使用:mvn dependency:unpack在命令行上配置此mojo以执行,则不得将配置放在executions标记内。您的配置应如下所示:

<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>代码并完美运行!