maven - 如何在maven中过滤测试资源?

标签 maven maven-resources-plugin

我有以下pom.xml。当我运行 mvn clean resources:testResources 时,我的测试资源不是 filtered (在将资源以修改后的形式放入输出文件夹之前替换资源中的占位符)。为什么?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>foo</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>
    <name>foo</name>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
</project>

最佳答案

resourcesresource 元素用于 resources:resources 目标。 resources:testResources 使用 testResourcestestResource 元素。

正确的pom.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>foo</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>
    <name>foo</name>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
    </build>
</project>

关于maven - 如何在maven中过滤测试资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24176399/

相关文章:

java - 如何从 maven pom 文件构建项目

maven - 如何在 maven-remote-resources-plugin 中使用 <includes>/<excludes>

java - 为什么 maven-resources-plugin 忽略我的字符集编码设置?

maven-resources-plugin 将资源副本中断到测试类

java - 在 Maven 项目中查找 JUnit 5 测试

java - 如何使用 Maven 在 Eclipse 中调试独立的 Java 程序?

java - Uber jar 不读取外部属性文件

android-maven-plugin 和资源过滤

maven - Spring Boot - 当您已经有父 pom 时父 pom

java - war 中的类(Class)有没有办法从它的耳朵访问 META-INF?