[英]Using maven-dependency-plugin inside maven profile
I have created a maven profile with maven-dependency-plugin inside it.我创建了一个 maven 配置文件,其中包含 maven-dependency-plugin。
Below is my plugin下面是我的插件
<profile>
<id>copy-dep</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-external</id>
<phase>none</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeGroupIds>group ids that I need to exclude</excludeGroupIds>
<excludeArtifactIds>artifact ids that I need to exclude</excludeArtifactIds>
<includeArtifactIds>artifact ids that I need to include</includeArtifactIds>
<includeGroupIds>group id that I need to include</includeGroupIds>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
I am using the below command to execute我正在使用以下命令执行
mvn dependency:copy-dependencies -DoutputDirectory=libs -Pcopy-dep
But when I execute the command it looks for all the dependencies defined in pom and copies them as well.但是当我执行命令时,它会查找 pom 中定义的所有依赖项并复制它们。
I have tried to put unwanted dependencies inside exclude tag but it didn't work then I also tried by removing exclude tag and keeping the required dependencies but also didn't worked.我试图将不需要的依赖项放在排除标记中,但它没有用,然后我还尝试删除排除标记并保留所需的依赖项,但也没有用。
In my pom, I am using maven assembly plugin to separate out the required dependencies, which I don't want to get copied with the created profile.在我的 pom 中,我使用 maven 程序集插件来分离出所需的依赖项,我不想与创建的配置文件一起复制这些依赖项。
Any idea where I am going wrong here?知道我在哪里出错了吗? is there a better way to achieve the same.有没有更好的方法来实现同样的目标。
To copy only "listed" artifacts (in this example it will copy only junit and mockito):要仅复制“列出的”工件(在此示例中,它将仅复制 junit 和 mockito):
<profile>
<id>copy-dep</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</artifactItem>
<artifactItem>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
and to execute it:并执行它:
mvn dependency:copy -Pcopy-dep
You need to tell Maven which execution to run.您需要告诉 Maven 要运行哪个执行。 So write:所以写:
mvn dependency:copy-dependencies@copy-external -DoutputDirectory=libs -Pcopy-dep
BTW: Putting this into a profile is probably not necessary.顺便说一句:可能没有必要将其放入配置文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.