我有一个带有父模块的项目。父母和孩子都使用maven-assembly-plugin。
父使用它自己的描述符(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>
这样:
<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>
而我的孩子的模块pom.xml有:
<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>
问题是子模块尝试使用zip.xml描述符并导致错误:
[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)
....
如果我从父maven-assembly-plugin
删除pom.xml
一切都很好,如果我再次添加,父任务工作正常,而子 - 失败。如何禁用描述符传播给孩子?
答案 0 :(得分:1)
首先创建一个单独的模块,如mod-assembly,并将maven-assembly-plugin的所有描述符和配置放入该模块,并使这个mod-assembly和您父项的其他子项。除此之外,使用更新的版本maven-assembly-plugin(2.4而不是2.2-beta-5)。