如何在使用 maven package 命令制作 zip 存档时添加其他目录?

How to add other directory while making zip archive using maven package command?

我有以下项目 maven 项目:

我想在 mvn package 命令创建的 zip 中添加 resourcescenarios 目录。

我在 pom.xml 中添加了 zip.xml 程序集和所需的插件:

src/main/assembly/zip.xml

<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>zip</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>./</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>./</outputDirectory>
            <includes>
                <include>/dependency-jars/</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

这是pom.xml:

<packaging>jar</packaging>
<dependencies>
     .....
</dependencies>
<build>

    <testResources>
        <testResource>
            <directory>${project.basedir}/config</directory>
        </testResource>
    </testResources>


    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerVersion>${sourceVersion}</compilerVersion>
                <source>${sourceVersion}</source>
                <target>${targetVersion}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <finalName>zip-with-dependencies</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptors>
                            <descriptor>src/main/assembly/zip.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>test-compile</id>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <source>${sourceVersion}</source>
                <target>${targetVersion}</target>
                <showWeaveInfo>true</showWeaveInfo>
                <complianceLevel>${sourceVersion}</complianceLevel>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>com.qmetry</groupId>
                        <artifactId>qaf</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>${testSuiteFile}</suiteXmlFile>
                </suiteXmlFiles>
                <reportsDirectory>${test.results.dir}/${run.time}</reportsDirectory>
                <systemPropertyVariables>
                    <org.uncommons.reportng.xml-dialect>testng</org.uncommons.reportng.xml-dialect>
                    <org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output>
                    <log4j.configuration>file:///${resource.dir}/log4j.properties</log4j.configuration>
                    <outputDir>${output.dir}</outputDir>
                    <test.results.dir>${output.dir}/html</test.results.dir>
                    <json.report.root.dir>${test.results.dir}</json.report.root.dir>
                    <json.report.dir>${output.dir}/json</json.report.dir>
                    <selenium.screenshots.dir>${output.dir}/img</selenium.screenshots.dir>
                    <selenium.screenshots.relative.path>../img</selenium.screenshots.relative.path>
                </systemPropertyVariables>
            </configuration>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>aspectj-maven-plugin</artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>test-compile</goal>
                                        <goal>compile</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

如有任何帮助,我们将不胜感激。谢谢

我明白了。我们可以在pom.xml中使用<testResources>来添加需要的目录。例如

<testResources>
    <testResource>
        <directory>${project.basedir}/resources</directory>
    </testResource>
</testResources>