【问题标题】:Include non Java files and resources files to test-jar using maven jar plugin使用 maven jar 插件将非 Java 文件和资源文件包含到 test-jar
【发布时间】:2013-01-09 09:57:44
【问题描述】:

我想包含脚本文件作为使用 maven 打包测试文件的一部分。我使用下面的插件配置但是配置和 jython 文件文件没有打包在测试 jar 中

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                    <configuration>
                        <includes>
                            <include>**/config/*</include>
                            <include>**/jython/*</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

有没有把不在 src/test/java 和 src/test/resources 中的文件包含在 test-jar 中?

【问题讨论】:

    标签: maven


    【解决方案1】:

    使用以下命令指定其他测试资源文件夹:

    <build>
        <testResources>
            <testResource>
                <directory>src/test</directory>
                <includes>
                    <include>**/config/*</include>
                    <include>**/jython/*</include>
                </includes>
            </testResource>
        </testResources>
    </build>
    

    然后您应该会发现 maven-jar-plugin 不需要任何配置。

    也可以使用 build-helper-maven-plugin。见:Maven - Add directory to classpath while executing tests

    【讨论】:

    • 很好的答案。我唯一要补充的是: 应该是 src/test/ (没有前导 /)而不是 / 它将扫描整个硬盘驱动器。
    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 2018-02-25
    • 2013-07-07
    • 2015-10-15
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多