maven-dependency-plugin 忽略 outputDirectory 配置
maven-dependency-plugin ignores outputDirectory configuration
我想用我的 java 主项目及其所有依赖项创建一个 jar 文件。所以我在 pom 文件中创建了以下插件定义:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- exclude junit, we need runtime dependency only -->
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
所以我执行 mvn dependency:copy-dependencies
,它工作正常,它将所有依赖项复制到 target/dependency
而不是 dependency-jars
。有什么想法吗?
这是正常的:您配置了一个名为 copy-dependencies
的特殊执行 maven-dependency-plugin
,但是,直接在命令行上调用目标 dependency:copy-dependencies
会创建一个默认执行,这与您配置的不同。因此,您的配置没有被考虑在内。
在 Maven 中,有 2 个地方可以配置插件:针对所有执行(在 <plugin>
级别使用 <configuration>
)或针对每个执行(在 <configuration>
级别使用 <configuration>
<execution>
水平)。
有几种方法可以解决您的问题:
将 <configuration>
移到 <execution>
之外,并使其对所有执行通用。你会:
<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>
请注意,有了这个,插件的所有执行都将使用此配置(除非在特定执行配置中被覆盖)。
在命令行上执行特定的执行,即您配置的那个。 This is possible since Maven 3.3.1 然后你会执行
mvn dependency:copy-dependencies@copy-dependencies
@copy-dependencies
用于引用要调用的执行的<id>
。
将您的执行绑定到 Maven 生命周期的特定阶段,并让它以生命周期的正常流程执行。在您的配置中,它已经与 <phase>package</phase>
绑定到 package
阶段。因此,调用 mvn clean package
将起作用并将您的依赖项复制到配置的位置。
我想用我的 java 主项目及其所有依赖项创建一个 jar 文件。所以我在 pom 文件中创建了以下插件定义:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- exclude junit, we need runtime dependency only -->
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
所以我执行 mvn dependency:copy-dependencies
,它工作正常,它将所有依赖项复制到 target/dependency
而不是 dependency-jars
。有什么想法吗?
这是正常的:您配置了一个名为 copy-dependencies
的特殊执行 maven-dependency-plugin
,但是,直接在命令行上调用目标 dependency:copy-dependencies
会创建一个默认执行,这与您配置的不同。因此,您的配置没有被考虑在内。
在 Maven 中,有 2 个地方可以配置插件:针对所有执行(在 <plugin>
级别使用 <configuration>
)或针对每个执行(在 <configuration>
级别使用 <configuration>
<execution>
水平)。
有几种方法可以解决您的问题:
将
<configuration>
移到<execution>
之外,并使其对所有执行通用。你会:<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>
请注意,有了这个,插件的所有执行都将使用此配置(除非在特定执行配置中被覆盖)。
在命令行上执行特定的执行,即您配置的那个。 This is possible since Maven 3.3.1 然后你会执行
mvn dependency:copy-dependencies@copy-dependencies
@copy-dependencies
用于引用要调用的执行的<id>
。将您的执行绑定到 Maven 生命周期的特定阶段,并让它以生命周期的正常流程执行。在您的配置中,它已经与
<phase>package</phase>
绑定到package
阶段。因此,调用mvn clean package
将起作用并将您的依赖项复制到配置的位置。