Reputation: 477
I have created a maven profile with maven-dependency-plugin inside it.
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.
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.
Any idea where I am going wrong here? is there a better way to achieve the same.
Upvotes: 1
Views: 1336
Reputation: 35795
You need to tell Maven which execution to run. So write:
mvn dependency:copy-dependencies@copy-external -DoutputDirectory=libs -Pcopy-dep
BTW: Putting this into a profile is probably not necessary.
Upvotes: 0
Reputation: 510
To copy only "listed" artifacts (in this example it will copy only junit and 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
Upvotes: 1