Как добавить другой каталог при создании zip-архива с помощью команды пакета maven? - PullRequest
0 голосов
/ 07 мая 2020

У меня есть проект maven ниже:

enter image description here

Я хотел бы добавить ресурс и сценарий * 1029 Каталог * в zip-архиве, созданный командой mvn package.

Я добавил zip.xml сборку и требуемый плагин в pom.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>

Любая помощь будет очень принята. Спасибо

1 Ответ

0 голосов
/ 08 мая 2020

Я разобрался. Мы можем использовать <testResources> в pom.xml, чтобы добавить требуемый каталог. например,

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