maven-dependency-plugin ignores outputDirectory configuration

限于喜欢 提交于 2019-12-01 08:25:40
Tunaki

That is normal: you configured a special execution of the maven-dependency-plugin, named copy-dependencies, however, invoking the goal dependency:copy-dependencies directly on the command line creates a default execution, which is different than the one you configured. Thus, your configuration isn't taken into account.

In Maven, there are 2 places where you can configure plugins: either for all executions (using <configuration> at the <plugin> level) or for each execution (using <configuration> at the <execution> level).

There are several ways to solve your issue:

  • Move the <configuration> outside of the <execution>, and make it general for all executions. You would have:

    <plugin>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.5.1</version>
      <configuration>
        <!-- exclude junit, we need runtime dependency only -->
        <includeScope>runtime</includeScope>
        <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
      </configuration>
    </plugin>
    

    Note that, with this, all executions of the plugin will use this configuration (unless overriden inside a specific execution configuration).

  • Execute on the command line a specific execution, i.e. the one you configured. This is possible since Maven 3.3.1 and you would execute

    mvn dependency:copy-dependencies@copy-dependencies
    

    The @copy-dependencies is used to refer to the <id> of the execution you want to invoke.

  • Bind your execution to a specific phase of the Maven lifecycle, and let it be executed with the normal flow of the lifecycle. In your configuration, it is already bound to the package phase with <phase>package</phase>. So, invoking mvn clean package would work and copy your dependencies at the configured location.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!