You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/09/30 07:18:01 UTC

(maven-resources-plugin) branch master updated: feat: add failOnMissingFilterValue parameter to fail on unresolved filter tokens (MRESOURCES-162)

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resources-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new b1325c3  feat: add failOnMissingFilterValue parameter to fail on unresolved filter tokens (MRESOURCES-162)
b1325c3 is described below

commit b1325c39095a769e121de0a36a560276427e6790
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Sep 30 09:17:56 2026 +0200

    feat: add failOnMissingFilterValue parameter to fail on unresolved filter tokens (MRESOURCES-162)
    
    - Add boolean `failOnMissingFilterValue` parameter (default: `false`) to `ResourcesMojo` that causes the build to fail when a filter expression cannot be resolved, instead of silently passing the placeholder through to the output
    - Wired into `MavenResourcesExecution` (requires maven-filtering 4.0.0-beta-3+)
    - Configurable via POM or `-Dmaven.resources.failOnMissingFilterValue=true`
    - Default `false` preserves full backward compatibility
    - Add IT `MRESOURCES-162-fail`: verifies build fails with unresolved token in error message
    - Add IT `MRESOURCES-162-pass`: verifies default behavior passes placeholder through
    
    Closes #400
---
 src/it/MRESOURCES-162-fail/invoker.properties      |  1 +
 src/it/MRESOURCES-162-fail/pom.xml                 | 57 ++++++++++++++++++++++
 .../src/main/resources/resource.txt                |  2 +
 src/it/MRESOURCES-162-fail/verify.groovy           | 25 ++++++++++
 src/it/MRESOURCES-162-pass/pom.xml                 | 54 ++++++++++++++++++++
 .../src/main/resources/resource.txt                |  2 +
 src/it/MRESOURCES-162-pass/verify.groovy           | 32 ++++++++++++
 .../maven/plugins/resources/ResourcesMojo.java     | 15 ++++++
 8 files changed, 188 insertions(+)

diff --git a/src/it/MRESOURCES-162-fail/invoker.properties b/src/it/MRESOURCES-162-fail/invoker.properties
new file mode 100644
index 0000000..fdd3d20
--- /dev/null
+++ b/src/it/MRESOURCES-162-fail/invoker.properties
@@ -0,0 +1 @@
+invoker.buildResult=failure
diff --git a/src/it/MRESOURCES-162-fail/pom.xml b/src/it/MRESOURCES-162-fail/pom.xml
new file mode 100644
index 0000000..3ddbb09
--- /dev/null
+++ b/src/it/MRESOURCES-162-fail/pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<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>org.apache.maven.plugins</groupId>
+  <artifactId>maven-resources-plugin-it-mresources-162-fail</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <!--
+    MRESOURCES-162: failOnMissingFilterValue=true
+    resource.txt references ${defined.property} (resolved) and ${missing.property} (not defined).
+    The build must FAIL with a MojoException mentioning the unresolved token.
+  -->
+  <properties>
+    <defined.property>hello</defined.property>
+    <!-- missing.property is intentionally not defined -->
+  </properties>
+
+  <build>
+    <resources>
+      <resource>
+        <filtering>true</filtering>
+        <directory>src/main/resources</directory>
+      </resource>
+    </resources>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>@project.version@</version>
+          <configuration>
+            <failOnMissingFilterValue>true</failOnMissingFilterValue>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
diff --git a/src/it/MRESOURCES-162-fail/src/main/resources/resource.txt b/src/it/MRESOURCES-162-fail/src/main/resources/resource.txt
new file mode 100644
index 0000000..d2d1be4
--- /dev/null
+++ b/src/it/MRESOURCES-162-fail/src/main/resources/resource.txt
@@ -0,0 +1,2 @@
+defined=${defined.property}
+missing=${missing.property}
diff --git a/src/it/MRESOURCES-162-fail/verify.groovy b/src/it/MRESOURCES-162-fail/verify.groovy
new file mode 100644
index 0000000..a3edf3f
--- /dev/null
+++ b/src/it/MRESOURCES-162-fail/verify.groovy
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// MRESOURCES-162: when failOnMissingFilterValue=true, the build must fail
+// and the error message must identify the unresolved token.
+def buildLog = new File( basedir, "build.log" )
+assert buildLog.text.contains( "BUILD FAILURE" )
+assert buildLog.text.contains( "missing.property" )
+return true
diff --git a/src/it/MRESOURCES-162-pass/pom.xml b/src/it/MRESOURCES-162-pass/pom.xml
new file mode 100644
index 0000000..0a9dd02
--- /dev/null
+++ b/src/it/MRESOURCES-162-pass/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<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>org.apache.maven.plugins</groupId>
+  <artifactId>maven-resources-plugin-it-mresources-162-pass</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <!--
+    MRESOURCES-162: failOnMissingFilterValue not set (defaults to false).
+    resource.txt references ${defined.property} (resolved) and ${missing.property} (not defined).
+    The build must SUCCEED and the output must contain the unresolved placeholder as-is.
+  -->
+  <properties>
+    <defined.property>hello</defined.property>
+    <!-- missing.property is intentionally not defined -->
+  </properties>
+
+  <build>
+    <resources>
+      <resource>
+        <filtering>true</filtering>
+        <directory>src/main/resources</directory>
+      </resource>
+    </resources>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-resources-plugin</artifactId>
+          <version>@project.version@</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
diff --git a/src/it/MRESOURCES-162-pass/src/main/resources/resource.txt b/src/it/MRESOURCES-162-pass/src/main/resources/resource.txt
new file mode 100644
index 0000000..d2d1be4
--- /dev/null
+++ b/src/it/MRESOURCES-162-pass/src/main/resources/resource.txt
@@ -0,0 +1,2 @@
+defined=${defined.property}
+missing=${missing.property}
diff --git a/src/it/MRESOURCES-162-pass/verify.groovy b/src/it/MRESOURCES-162-pass/verify.groovy
new file mode 100644
index 0000000..150ffd9
--- /dev/null
+++ b/src/it/MRESOURCES-162-pass/verify.groovy
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// MRESOURCES-162: when failOnMissingFilterValue is not set (defaults to false),
+// the build succeeds and the unresolved placeholder is passed through as-is.
+import org.codehaus.plexus.util.FileUtils
+
+def resource = new File( basedir, "target/classes/resource.txt" )
+assert resource.exists()
+
+def content = FileUtils.fileRead( resource )
+// defined.property must be resolved
+assert content.contains( "defined=hello" )
+// missing.property must be passed through literally
+assert content.contains( 'missing=${missing.property}' )
+return true
diff --git a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
index ad4d4c2..8327e06 100644
--- a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
@@ -419,6 +419,20 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo {
     @Parameter(property = "maven.resources.skip", defaultValue = "false")
     private boolean skip;
 
+    /**
+     * When set to {@code true}, the build fails if a filter expression in a resource file cannot be resolved
+     * (i.e. the placeholder is left unsubstituted in the output). For example, if a resource contains
+     * {@code ${missing.property}} and no property with that name is defined, the build will fail instead
+     * of copying the literal text {@code ${missing.property}} to the output.
+     * <p>
+     * Defaults to {@code false} to preserve backward compatibility.
+     * </p>
+     *
+     * @since 4.0.0-beta-2
+     */
+    @Parameter(property = "maven.resources.failOnMissingFilterValue", defaultValue = "false")
+    private boolean failOnMissingFilterValue;
+
     @Inject
     private Log logger;
 
@@ -507,6 +521,7 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo {
             } else {
                 mavenResourcesExecution.setNonFilteredFileExtensions(ADDITIONAL_DEFAULT_NON_FILTERED_EXTENSIONS);
             }
+            mavenResourcesExecution.setFailOnMissingFilterValue(failOnMissingFilterValue);
             mavenResourcesFiltering.filterResources(mavenResourcesExecution);
 
             executeUserFilterComponents(mavenResourcesExecution);