如何防止'创建程序集归档分发时出错:zip文件不能包含自身'

时间:2015-11-26 19:06:30

标签: maven maven-assembly-plugin

我有一个多模块项目,我想用所有来源(和其他文件)制作一个zip。我使用maven-assemble-plugin

我找到了dependencySet的方法,但我不希望将所有模块源(以及后来的javadoc)添加为依赖项。我尝试使用moduleSet,但收到错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (make-zip) on project test-distribution: Failed to create assembly: Error creating assembly archive distribution: A zip file cannot include itself -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (make-zip) on project test-distribution: Failed to create assembly: Error creating assembly archive distribution: A zip file cannot include itself

我的pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>make-zip</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>src/assemble/distribution.xml</descriptor>
                </descriptors>
                <appendAssemblyId>false</appendAssemblyId>
                <finalName>test</finalName> 
            </configuration>
        </execution>
    </executions>
</plugin>

我的汇编描述符:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">

    <id>distribution</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <moduleSets>
        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>
             <sources>
                 <outputDirectory>/Sources</outputDirectory>
             </sources>
        </moduleSet>
    </moduleSets>
</assembly>

使用dependencySet我可以使用选项useProjectArtifact解决该问题,但我找不到moduleSet的选项。有没有办法排除当前项目的构建?

1 个答案:

答案 0 :(得分:0)

我找到了exclude当前项目构建的方法:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">

    <id>distribution</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <moduleSets>
        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>
            <excludes>
                <exclude>*:test-distribution</exclude>
            </excludes>
            <sources>
                <outputDirectory>/Sources</outputDirectory>
            </sources>
        </moduleSet>
    </moduleSets>
</assembly>