Question

I want Maven to download and put jetty-runner.jar dependency into myproject/target/dependency folder.

Part of my pom.xml:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals><goal>copy</goal></goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.eclipse.jetty</groupId>
                                    <artifactId>jetty-runner</artifactId>
                                    <version>9.1.1.v20140108</version>
                                    <destFileName>jetty-runner.jar</destFileName>
                                    <outputDirectory>${project.build.directory}/dependency</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

However, when I do mvn package from my project directory the jetty-runner.jar is not copied to /target/dependency folder.

What WORKS however is when I add the following line to <configuration>:

<id>default-cli</id>

and run it with mvn dependency:copy.

What am I missing?

Was it helpful?

Solution

When you configure the maven-dependency-plugin within the <pluginManagement> section, maven will do nothing with it. Your <pluginManagement> section does only define how the maven-dependency-plugin will be configured in case it is invoked. To actually invoke the plugin during the packaging phase, you need to define the invocation in the <plugins> section.

So you can either move the whole plugin configuration from <pluginManamgement> to <plugins> or you can additionally define the maven-dependency-plugin without version and configuration in the <plugins> section:

<build>
  <plugins>
    <!-- no need for version or configuration since both are defined in pluginManagement -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
    </plugin>
    ...
  </plugins>
  ...
</build>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top