ovnia
ovnia

Reputation: 2500

Maven Assembly plugin parent descriptor sharing

I have a project, with a parent module. Parent and child both using maven-assembly-plugin.

Parent uses it's own descriptor (zip.xml):

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>bin</id>
    <includeBaseDirectory>false</includeBaseDirectory>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${svn.scripts}</directory>
            <includes>
                <include>query.*</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${cfgreader.dist}</directory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

this way:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptor>${basedir}/descriptors/zip.xml</descriptor>
                <finalName>${patch.prefix}_rev</finalName>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

while my child's module pom.xml has:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>com.test.cfgReader</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <finalName>cfgreader</finalName>
            <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

The problem is that the child module tries to use zip.xml descriptor and it causes errors:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.
2-beta-5:single (make-assembly) on project dist: Error reading assemblies: Error
 locating assembly descriptor: D:\dist/descriptors/zip.xml
[ERROR]
[ERROR] [1] [INFO] Searching for file location: D:\dist\D\dist\D:\dist\descriptors\zip.xml
[ERROR]
[ERROR] [2] [INFO] File: D:\\dist\D:\\dist\descriptors\zip.xml does not exist.
[ERROR]
[ERROR] [3] [INFO] Invalid artifact specification: 'D:\\dist\D:\\dist\descriptors\zip.xml'. Must contain at le
ast three fields, separated by ':'.
[ERROR]
[ERROR] [4] [INFO] Failed to resolve classpath resource: assemblies/D:\dist/descriptors/zip.xml from
 classloader: ClassRealm[plugin>org.apache.maven.plugins:maven-assembly-plugin:2
.2-beta-5, parent: sun.misc.Launcher$AppClassLoader@33d626a4]
[ERROR]
[ERROR] [5] [INFO] Failed to resolve classpath resource: D:\dist/descriptors/zip.xml from classloade
r: ClassRealm[plugin>org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5,
parent: sun.misc.Launcher$AppClassLoader@33d626a4]
[ERROR]
[ERROR] [6] [INFO] File: D:\D\descriptors\zip.xml does not exist.
[ERROR]
[ERROR] [7] [INFO] Building URL from location: D:\dist/descriptors/zip.xml
[ERROR] Error:
[ERROR] java.net.MalformedURLException: unknown protocol: d
[ERROR] at java.net.URL.<init>(URL.java:592)
[ERROR] at java.net.URL.<init>(URL.java:482)
[ERROR] at java.net.URL.<init>(URL.java:431)
[ERROR] at org.apache.maven.shared.io.location.URLLocatorStrategy.resolve(URLLoc
atorStrategy.java:54)

.... and if i delete maven-assembly-plugin from parent pom.xml everything is fine, if i add again, parent task works fine, while child - fails. how to disable descriptor propagation to childs?

Upvotes: 0

Views: 1600

Answers (1)

khmarbaise
khmarbaise

Reputation: 97487

First create a separate module like mod-assembly and put all the descriptors and configuration for the maven-assembly-plugin into that module and make this mod-assembly and other child of your parent. Apart from that use a more up-to-date version maven-assembly-plugin (2.4 instead of 2.2-beta-5).

Upvotes: 1

Related Questions