我有一个有5个依赖项的maven项目。其中两个(具有传递依赖性)我需要在自定义位置,让我们说在client/plugins
。我需要在另一个位置使用其他项目依赖项(也包含传递依赖项),让我们在client/modules
中说。以下来自Apache Maven文档的示例,这是我的<build>
块:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.groupid</groupId>
<artifactId>my-artifactid-one</artifactId>
<version>1.0-SNAPSHOT</version>
<outputDirectory>client/modules</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>my.groupid</groupId>
<artifactId>my-artifactid-one</artifactId>
<version>1.1-SNAPSHOT</version>
<outputDirectory>client/modules</outputDirectory>
</artifactItem>
</artifactItems>
<outputDirectory>client/plugins</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
当我运行mvn -U clean package
命令时,Maven将所有项目依赖项及其传递依赖项复制到client/plugins
。因此,它忽略了我为特定工件设置的配置。
我该如何设置?
答案 0 :(得分:0)
看起来只使用一个目标就无法实现这一目标。所以我定义了两个copy-dependencies
目标。然后指定不同的输出目录并使用excludeArtifactIds
参数来排除不需要的工件。它看起来像这样:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-plugins</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>client/plugins</outputDirectory>
<excludeArtifactIds>module-artifact-one, module-artifact-two </excludeArtifactIds>
</configuration>
</execution>
<execution>
<id>copy-modules</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>client/modules</outputDirectory>
<excludeArtifactIds>plugin-artifact-one, plugin-artifact-two</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我运行mvn -U clean package
,它现在正常运作。