0

我正在尝试构建一个 testng fatjar,但看起来这个配置没有添加来自 java main 和测试的资源

   <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <argLine>--enable-preview</argLine>
                <descriptor>src/main/assembly/assembly.xml</descriptor>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>

这是配置 assembly.xml

<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>fat-tests</id>
<formats>
    <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <useProjectArtifact>true</useProjectArtifact>
        <unpack>true</unpack>
        <scope>test</scope>
    </dependencySet>
</dependencySets>
<fileSets>
    <fileSet>
        <directory>${project.build.directory}/test-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.class</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}/test-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.xml</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
</fileSets>

我尝试了不同的目标和配置,但找不到如何将所有文件夹添加到 jar、来自 java 的资源和测试文件夹。

4

1 回答 1

1

要从 target/classes 和 target/test-classes 文件夹复制所有资源,请尝试以下文件。所有资源将被复制到 jar 文件中的根文件夹中。

<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>fat-tests</id>
<formats>
    <format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <useProjectArtifact>true</useProjectArtifact>
        <unpack>true</unpack>
        <scope>test</scope>
    </dependencySet>
</dependencySets>
<fileSets>
<fileSet>
        <directory>${project.build.directory}/classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.*</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}/test-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.class</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}/test-classes</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/*.*</include>
        </includes>
        <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
</fileSets>
于 2020-11-23T07:05:02.813 回答