maven-dependency-plugin ignores outputDirectory configuration

后端 未结 1 1405
不知归路
不知归路 2021-01-06 21:19

I want to create a jar file with my main java project and all of it\'s dependencies. so I created the following plugin definition in the pom file:



        
相关标签:
1条回答
  • 2021-01-06 21:44

    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.

    0 讨论(0)
提交回复
热议问题