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/25 07:57:02 UTC
(maven-resources-plugin) branch fix/change-detection created (now 2a7bc94)
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a change to branch fix/change-detection
in repository https://gitbox.apache.org/repos/asf/maven-resources-plugin.git
at 2a7bc94 [MRESOURCES-453] Leverage ChangeDetection from maven-filtering #397
This branch includes the following new commits:
new 2a7bc94 [MRESOURCES-453] Leverage ChangeDetection from maven-filtering #397
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-resources-plugin) 01/01: [MRESOURCES-453] Leverage ChangeDetection from maven-filtering #397
Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch fix/change-detection
in repository https://gitbox.apache.org/repos/asf/maven-resources-plugin.git
commit 2a7bc949a640c3e584f8d7f679b7ec26910bec0a
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Sep 25 07:56:50 2026 +0000
[MRESOURCES-453] Leverage ChangeDetection from maven-filtering #397
Replace the deprecated boolean 'overwrite' parameter with a 'changeDetection'
strategy enum (CONTENT / TIMESTAMP / TIMESTAMP_AND_CONTENT / ALWAYS / NEVER),
forwarded from maven-filtering 4.0.0-beta-2-SNAPSHOT (PR apache/maven-filtering#397).
- Add 'changeDetection' @Parameter (default CONTENT, i.e. current behaviour)
- Deprecate 'overwrite'; bridge: overwrite=true maps to ALWAYS, overwrite=false
keeps the declared changeDetection value (backward-compat)
- Add IT MRESOURCES-453: verifies that changeDetection=NEVER leaves an existing
destination file untouched even when source content differs
Fixes: https://github.com/apache/maven-resources-plugin/issues/453
Depends on: apache/maven-filtering#397
---
pom.xml | 2 +-
src/it/MRESOURCES-453/invoker.properties | 19 ++++++++
src/it/MRESOURCES-453/pom.xml | 50 ++++++++++++++++++++++
src/it/MRESOURCES-453/setup.groovy | 32 ++++++++++++++
.../MRESOURCES-453/src/main/resources/resource.txt | 1 +
src/it/MRESOURCES-453/verify.groovy | 33 ++++++++++++++
.../maven/plugins/resources/ResourcesMojo.java | 46 +++++++++++++++++++-
7 files changed, 181 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8e4bca6..83ca11e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,7 +76,7 @@ under the License.
<javaVersion>17</javaVersion>
<guiceVersion>7.0.0</guiceVersion>
- <mavenFilteringVersion>4.0.0-beta-1</mavenFilteringVersion>
+ <mavenFilteringVersion>4.0.0-beta-2-SNAPSHOT</mavenFilteringVersion>
<mavenPluginPluginVersion>4.0.0-beta-2</mavenPluginPluginVersion>
<mavenPluginTestingVersion>4.0.0-beta-4</mavenPluginTestingVersion>
<plexusBuildApiVersion>0.0.7</plexusBuildApiVersion>
diff --git a/src/it/MRESOURCES-453/invoker.properties b/src/it/MRESOURCES-453/invoker.properties
new file mode 100644
index 0000000..427d067
--- /dev/null
+++ b/src/it/MRESOURCES-453/invoker.properties
@@ -0,0 +1,19 @@
+# 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.
+
+# Skip 'clean' so that the destination file pre-seeded by setup.groovy survives into process-resources.
+invoker.goals = process-resources
diff --git a/src/it/MRESOURCES-453/pom.xml b/src/it/MRESOURCES-453/pom.xml
new file mode 100644
index 0000000..8fce608
--- /dev/null
+++ b/src/it/MRESOURCES-453/pom.xml
@@ -0,0 +1,50 @@
+<?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-453</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <description>Verifies that changeDetection=NEVER leaves an already-existing destination file untouched,
+ even when the source content differs (regression test for MRESOURCES-453).</description>
+
+ <build>
+ <resources>
+ <resource>
+ <filtering>false</filtering>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <changeDetection>NEVER</changeDetection>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/src/it/MRESOURCES-453/setup.groovy b/src/it/MRESOURCES-453/setup.groovy
new file mode 100644
index 0000000..f309060
--- /dev/null
+++ b/src/it/MRESOURCES-453/setup.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.
+ */
+
+// Pre-populate the output directory with content that differs from the source,
+// simulating a later build step that modified the copied resource.
+// With changeDetection=NEVER the plugin must leave this file untouched.
+
+import java.nio.file.*
+
+def outputDir = new File(basedir, "target/classes")
+outputDir.mkdirs()
+
+def dest = new File(outputDir, "resource.txt")
+dest.text = "modified by build step\n"
+
+return true
diff --git a/src/it/MRESOURCES-453/src/main/resources/resource.txt b/src/it/MRESOURCES-453/src/main/resources/resource.txt
new file mode 100644
index 0000000..2fd0152
--- /dev/null
+++ b/src/it/MRESOURCES-453/src/main/resources/resource.txt
@@ -0,0 +1 @@
+original content
diff --git a/src/it/MRESOURCES-453/verify.groovy b/src/it/MRESOURCES-453/verify.groovy
new file mode 100644
index 0000000..5a9e73b
--- /dev/null
+++ b/src/it/MRESOURCES-453/verify.groovy
@@ -0,0 +1,33 @@
+/*
+ * 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-453: changeDetection=NEVER must not overwrite a destination file that already exists,
+// even when the source content differs from what is currently on disk.
+
+import java.nio.file.*
+
+def outputDir = new File(basedir, "target/classes")
+def dest = new File(outputDir, "resource.txt")
+
+// Pre-condition: the invoker should have run process-resources once already (setup via invoker.properties).
+// We verify the file exists with the pre-placed sentinel content, not with the source content.
+assert dest.exists() : "Destination file must exist after process-resources"
+assert dest.text == "modified by build step\n" : "changeDetection=NEVER must leave the existing file untouched; found: '${dest.text}'"
+
+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 63539e0..a803c3f 100644
--- a/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/resources/ResourcesMojo.java
@@ -38,6 +38,7 @@ import org.apache.maven.api.plugin.MojoException;
import org.apache.maven.api.plugin.annotations.Mojo;
import org.apache.maven.api.plugin.annotations.Parameter;
import org.apache.maven.api.services.ProjectManager;
+import org.apache.maven.shared.filtering.ChangeDetection;
import org.apache.maven.shared.filtering.MavenFilteringException;
import org.apache.maven.shared.filtering.MavenResourcesExecution;
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
@@ -152,11 +153,34 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo {
@Parameter
protected String escapeString;
+ /**
+ * Strategy used to decide whether an existing destination file needs to be overwritten.
+ * Accepted values:
+ * <ul>
+ * <li>{@code CONTENT} — (default) only overwrite when the content differs (uses
+ * {@code CachingOutputStream} / {@code CachingWriter}); destination timestamp is
+ * preserved when the content is identical. This is the behaviour since 3.4.0.</li>
+ * <li>{@code TIMESTAMP} — only overwrite when the source is newer than the destination
+ * (timestamp-based, as it was before 3.4.0).</li>
+ * <li>{@code TIMESTAMP_AND_CONTENT} — overwrite only when the source is newer
+ * <em>and</em> the content differs.</li>
+ * <li>{@code ALWAYS} — always overwrite existing files (equivalent to the former
+ * {@code <overwrite>true</overwrite>}).</li>
+ * <li>{@code NEVER} — never overwrite an existing destination file.</li>
+ * </ul>
+ *
+ * @since 3.4.0
+ */
+ @Parameter(defaultValue = "CONTENT", property = "maven.resources.changeDetection")
+ private ChangeDetection changeDetection;
+
/**
* Overwrite existing files even if the destination files are newer.
*
* @since 2.3
+ * @deprecated Use {@link #changeDetection} with {@code ALWAYS} instead.
*/
+ @Deprecated
@Parameter(defaultValue = "false")
private boolean overwrite;
@@ -341,7 +365,9 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo {
mavenResourcesExecution.setInjectProjectBuildFilters(false);
mavenResourcesExecution.setEscapeString(escapeString);
- mavenResourcesExecution.setOverwrite(overwrite);
+ // Resolve change detection: deprecated 'overwrite=true' maps to ALWAYS; otherwise use changeDetection.
+ ChangeDetection effectiveDetection = overwrite ? ChangeDetection.ALWAYS : changeDetection;
+ mavenResourcesExecution.setChangeDetection(effectiveDetection);
mavenResourcesExecution.setIncludeEmptyDirs(includeEmptyDirs);
mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
mavenResourcesExecution.setFilterFilenames(fileNameFiltering);
@@ -489,16 +515,34 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo {
this.outputDirectory = outputDirectory;
}
+ /**
+ * @return {@link #changeDetection}
+ */
+ public ChangeDetection getChangeDetection() {
+ return changeDetection;
+ }
+
+ /**
+ * @param changeDetection the change detection strategy to use.
+ */
+ public void setChangeDetection(ChangeDetection changeDetection) {
+ this.changeDetection = changeDetection;
+ }
+
/**
* @return {@link #overwrite}
+ * @deprecated Use {@link #getChangeDetection()} instead.
*/
+ @Deprecated
public boolean isOverwrite() {
return overwrite;
}
/**
* @param overwrite true to overwrite false otherwise.
+ * @deprecated Use {@link #setChangeDetection(ChangeDetection)} instead.
*/
+ @Deprecated
public void setOverwrite(boolean overwrite) {
this.overwrite = overwrite;
}