我建立一个多模块的Maven项目,其主要产品是一个WAR文件,我试图与相关联的发行有关的文物(自述,发行说明,许可文件等)转化为一个ZIP聚集在一起该文件分配。但是,当我尝试建立一个分发文件,它失败。我究竟做错了什么?请注意,我已经检查了foo-bar.1.0.war
神器存在于该foo-distribution
模块被要求建立分发文件的地步;我知道,在foo
的POM把一切将无法正常工作。 (我有一种解决方法;我可以使用相对路径来直接指向相对于foo-distribution
模块根分配的文件的位置这不是我喜欢,因为它有坏代码气味的溶液。)
还请注意,我总是从根项目建设,而且我在分配Builder中使用assembly:single
(作为Maven的文档中推荐)。
foo
+ src
| + README.txt
+ foo-bar
| + target
| + foo-bar.1.0.war
+ foo-distribution
+ src
+ assemble
+ dist.xml
foo
和foo-distribution
有pom
包装,并foo-bar
有war
包装。 (这里是真正的代码的其它模块,但他们也foo-distribution
模块之前构建正确。)
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>foobar</groupId>
<artifactId>foo</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<modules>
<module>foo-bar</module>
<module>foo-distribution</module>
</modules>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>foo</artifactId>
<groupId>foobar</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>foobar</groupId>
<artifactId>foo-distribution</artifactId>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>foobar</groupId>
<artifactId>foo-bar</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<finalName>foobar</finalName>
<descriptors>
<descriptor>src/assemble/dist.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-t2server-distribution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<moduleSets>
<moduleSet>
<includes>
<include>foobar:foo</include>
</includes>
<sources>
<fileSets>
<fileSet>
<directory>src</directory>
<includes>
<include>*.txt</include>
</includes>
</fileSet>
</fileSets>
</sources>
</moduleSet>
<moduleSet>
<includes>
<include>foobar:foo-bar</include>
</includes>
<binaries />
</moduleSet>
</moduleSets>
</assembly>
这就是我上面提到的解决方法。它产生正是我想要的神器。
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}/../src</directory>
<includes>
<include>*.txt</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/../foo-bar/target</directory>
<includes>
<include>*.war</include>
</includes>
<outputDirectory>.</outputDirectory>
</fileSet>
</fileSets>
</assembly>
你应该在你的装配描述符使用dependencySet
<assembly>
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useTransitiveDependencies>false</useTransitiveDependencies>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
<fileMode>0644</fileMode>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
with all supplemental files you need
</fileSet>
</fileSets>
代替经由文件系统(相对路径)引用的文件。而在另一方面,对于源的描述确实从组件插件已经存在(看看到文档)。
什么顺序模块存在的身材,我也有类似的问题,述说家长与构建顺序帮助孩子模块中。如果使用不知道可以在这方面帮助。