maven-dependency-plugin:unpack Error

PistolPete picture PistolPete · May 15, 2015 · Viewed 14.4k times · Source

I'm trying to extract some .exe files from a dependency jar file and put them under ${project.build.directory}/classes/.

But when I execute:

mvn clean compile dependency:unpack

I get:

Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack (default-cli) on project simple: Either artifact or artifactItems is required -> [Help 1

I have verified that the dependencies are available in my local repository.

In my example pom below I've used junit as an example, but no matter which dependency I list, I get the same error.

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>

Answer

King Midas picture King Midas · May 18, 2015

The issue is due to you cannot use mvn clean compile dependency:unpack and <executions> tags together.

In documentation Maven Depdendency Plugin at the bottom part of the page you can read:

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>

I have tried removing the <execution> tags and works perfectly!