I'm trying to have a Project B pull down (and unpack) a ZIP built by Project A and deployed to a remote repository.
The ZIP is created and attached using the maven-assembly-plugin
, with packaging type pom
:
<artifactId>project-a</artifactId>
<name>ZIP</name>
<description>Used by Project B</description>
<packaging>pom</packaging>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distribution-package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/scripts.xml</descriptor>
</descriptors>
<tarLongFileMode>gnu</tarLongFileMode>
</configuration>
</execution>
</executions>
</plugin>
Attempting to pull it down from Project B's pom with the maven-dependency-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-scripts</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/staging</outputDirectory>
<stripVersion>true</stripVersion>
<artifactItems>
<artifactItem>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<overWrite>true</overWrite>
<type>zip</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
fails with: [ERROR] Failed to execute goal on project ...: Could not resolve dependencies for project group:artifact:pom:version: Could not find artifact group:project-a:zip:version in nexus (http://...:8081/nexus/content/groups/public) -> [Help 1]
I would assume this is because I specified Project A's packaging as pom
and not zip
, however I can't specify Project A as packaging type zip
because it results in:
[ERROR] Unknown packaging: zip @ line 13, column 13
Am I doing something wrong here or is this simply not possible?
I just have a bunch of files that I want to bundle up into an artifact and allow multiple other projects to download and unpack them for use. Open to different suggestions...
I've also checked to make sure that the assembled zip is indeed in the nexus.
UPDATED WITH ANSWER
For anyone else's benefit, what I was missing is that the <classifier>
of the dependency has to match the <id>
of the assembly. Notice where thisistheattachedartifactsclassifier
is specified in the following files.
scripts.xml (Project A):
<assembly>
<id>thisistheattachedartifactsclassifier</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
...
</fileSet>
</fileSets>
</assembly>
pom.xml (Project B):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-scripts</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/staging</outputDirectory>
<stripVersion>true</stripVersion>
<artifactItems>
<artifactItem>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<classifier>thisistheattachedartifactsclassifier</classifier>
<overWrite>true</overWrite>
<type>zip</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…