You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2026/08/06 11:34:40 UTC

(maven-build-cache-extension) branch master updated: Issue #496 Support maven.build.cache.skipSave as module-level property (#497)

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

olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-build-cache-extension.git


The following commit(s) were added to refs/heads/master by this push:
     new 58524175 Issue #496 Support maven.build.cache.skipSave as module-level property (#497)
58524175 is described below

commit 585241758ef7f3623878056192df50cbc37def56
Author: alascbio <al...@ext.biomerieux.com>
AuthorDate: Thu Aug 6 13:34:35 2026 +0200

    Issue #496 Support maven.build.cache.skipSave as module-level property (#497)
---
 documentation/extension-features-test-plan.md      | 18 ++++++------
 .../BuildCacheMojosExecutionStrategy.java          |  3 +-
 .../buildcache/checksum/MavenProjectInput.java     | 12 ++++++++
 src/site/markdown/parameters.md                    |  1 +
 .../maven/buildcache/its/PerModuleFlagsTest.java   | 11 ++++++++
 .../per-module-flags/{ => module4}/pom.xml         | 33 ++++++++--------------
 .../java/org/apache/maven/buildcache/Test4.java    | 24 ++++++++++++++++
 src/test/projects/per-module-flags/pom.xml         |  1 +
 8 files changed, 71 insertions(+), 32 deletions(-)

diff --git a/documentation/extension-features-test-plan.md b/documentation/extension-features-test-plan.md
index c6a09440..0ba7f56d 100644
--- a/documentation/extension-features-test-plan.md
+++ b/documentation/extension-features-test-plan.md
@@ -301,12 +301,12 @@ This reference drives the correctness test cases in Group Q and `CacheInvalidati
 
 | ID   | Feature                                                 | XML / System Property                           | Status | Test Reference                                                          |
 |------|---------------------------------------------------------|-------------------------------------------------|--------|-------------------------------------------------------------------------|
-| F8.1 | Full reactor — each module independently cached         | implicit                                        | ✅      | `Issue21Test`, `UpstreamModuleChangeDownstreamMissTest`                 |
-| F8.2 | Partial reactor (`-pl`) — targeted modules cached       | implicit `-pl`                                  | ✅      | `multimodule/MultiModulePartialBuildTest`                               |
-| F8.3 | Partial reactor with upstream restore (`-pl -am`)       | implicit `-pl -am`                              | ✅      | `multimodule/MultiModulePartialWithAmTest`                              |
-| F8.4 | Parallel builds (`-T`) — no cross-thread corruption     | implicit `-T`                                   | ✅      | `multimodule/ParallelBuildTest`                                         |
-| F8.5 | `scanProfiles` — include active profiles in cache key   | `<multiModule><scanProfiles>`                   | ✅      | `multimodule/ScanProfilesTest`                                          |
-| F8.6 | Per-module `skipCache` / `enabled` override via POM     | `maven.build.cache.skipCache` / `.enabled`      | ✅      | `PerModuleFlagsTest`                                                    |
+| F8.1 | Full reactor — each module independently cached                      | implicit                                        | ✅      | `Issue21Test`, `UpstreamModuleChangeDownstreamMissTest`                 |
+| F8.2 | Partial reactor (`-pl`) — targeted modules cached                    | implicit `-pl`                                  | ✅      | `multimodule/MultiModulePartialBuildTest`                               |
+| F8.3 | Partial reactor with upstream restore (`-pl -am`)                    | implicit `-pl -am`                              | ✅      | `multimodule/MultiModulePartialWithAmTest`                              |
+| F8.4 | Parallel builds (`-T`) — no cross-thread corruption                  | implicit `-T`                                   | ✅      | `multimodule/ParallelBuildTest`                                         |
+| F8.5 | `scanProfiles` — include active profiles in cache key                | `<multiModule><scanProfiles>`                   | ✅      | `multimodule/ScanProfilesTest`                                          |
+| F8.6 | Per-module `skipCache` / `skipSave` / `enabled` override via POM     | `maven.build.cache.skipCache` / `.enabled`      | ✅      | `PerModuleFlagsTest`                                                    |
 | F8.7 | Subtree build of leaf module — cache hit via `rootDirectory` anchor     | implicit (`.mvn/` traversal)                    | ✅      | `multimodule/SubtreeBuildCacheHitTest#subtreeBuildHitsCacheAfterFullReactorBuild`                          |
 | F8.8 | Partial reactor with upstream dep — `-am` puts B in `session.getProjects()` so checksum matches; no discovery config | implicit `-pl -am`                              | ✅      | `multimodule/SubtreeBuildCacheHitTest#partialReactorWithAmHitsCacheWithoutDiscovery`                       |
 | F8.9 | Subtree build with upstream dep + `<discovery><scanProfiles>` — full re-scan from root activates profile, discovers B with matching effective model | `<multiModule><discovery><scanProfiles>`         | ✅      | `multimodule/SubtreeBuildCacheHitTest#subtreeWithDiscoveryAndScanProfileHitsCacheAfterFullReactorBuild`    |
@@ -529,7 +529,7 @@ cache behaviors are project-agnostic.
 | ID   | Scenario                                          | Features   | Reference Project         | Status                                                 |
 |------|---------------------------------------------------|------------|---------------------------|--------------------------------------------------------|
 | I-01 | Full reactor: each module independently cached    | F8.1       | legacy: `build-extension` | ✅ `Issue21Test`                                        |
-| I-02 | Per-module skipCache / disabled via POM           | F8.6       | **P10**                   | ✅ `PerModuleFlagsTest`                                 |
+| I-02 | Per-module skipCache / skipSave /disabled via POM | F8.6       | **P10**                   | ✅ `PerModuleFlagsTest`                                 |
 | I-03 | Upstream module change → downstream miss          | F8.1       | **P02**                   | ✅ `multimodule/UpstreamModuleChangeDownstreamMissTest` |
 | I-04 | Partial reactor `-pl module`                      | F8.2       | **P10**                   | ✅ `multimodule/MultiModulePartialBuildTest`            |
 | I-05 | Partial reactor `-pl module -am` upstream restore | F8.3       | **P10**                   | ✅ `multimodule/MultiModulePartialWithAmTest`           |
@@ -668,7 +668,7 @@ Master traceability table mapping behaviors to test classes and reference projec
 | TC-027 | Forked lifecycle execution tracked and cached                              | `ForkedExecutionsTest`                                        | P12                               | ✅      |
 | TC-028 | Duplicate goal executions deduped correctly                                | `DuplicateGoalsTest`                                          | P01                               | ✅      |
 | TC-029 | logAll flag dumps all mojo properties                                      | `LogAllPropertiesTest`                                        | P19                               | ✅      |
-| TC-030 | Per-module skipCache via POM property                                      | `PerModuleFlagsTest`                                          | P10                               | ✅      |
+| TC-030 | Per-module skipCache / skipSave via POM property                           | `PerModuleFlagsTest`                                          | P10                               | ✅      |
 | TC-031 | Per-module cache disabled via POM property                                 | `PerModuleFlagsTest`                                          | P10                               | ✅      |
 | TC-032 | `skipCache=true` global: rebuilds all, still writes                        | `SkipBuildExtensionTest`                                      | PARAM P01-P19                     | ✅      |
 | TC-033 | `skipSave=true`: reads cache, does not write                               | `BuildExtensionTest.skipSaving`                               | PARAM P01-P19                     | ✅      |
@@ -809,7 +809,7 @@ All `maven.build.cache.*` properties recognized by `CacheConfigImpl`. Resolution
 | `maven.build.cache.restoreOnDiskArtifacts`  | `true`                                                 | boolean    | — (CLI / POM property)                             |
 | `maven.build.cache.alwaysRunPlugins`        | —                                                      | comma-list | `<executionControl><runAlways>` (partial override) |
 | `maven.build.cache.skipCache`               | `false`                                                | boolean    | — (CLI / POM property)                             |
-| `maven.build.cache.skipSave`                | `false`                                                | boolean    | — (CLI only)                                       |
+| `maven.build.cache.skipSave`                | `false`                                                | boolean    | — (CLI / POM property)                             |
 | `maven.build.cache.mandatoryClean`          | `false`                                                | boolean    | `<configuration><mandatoryClean>`                  |
 | `maven.build.cache.processPlugins`          | `true`                                                 | boolean    | — (POM property per-project)                       |
 | `maven.build.cache.input.glob`              | —                                                      | glob       | `<input><global><glob>` (per-project override)     |
diff --git a/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java b/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
index 33b6f011..a09f9216 100644
--- a/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
+++ b/src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
@@ -175,7 +175,8 @@ public void execute(
                 }
 
                 if (cacheState == INITIALIZED && (!result.isSuccess() || !restored)) {
-                    if (cacheConfig.isSkipSave()) {
+                    boolean skipSave = cacheConfig.isSkipSave() || MavenProjectInput.isSkipSave(project);
+                    if (skipSave) {
                         LOGGER.debug("Cache saving is disabled.");
                     } else if (cacheConfig.isMandatoryClean()
                             && lifecyclePhasesHelper
diff --git a/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java b/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
index 6145e475..ff043f34 100644
--- a/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
+++ b/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java
@@ -101,6 +101,7 @@
 import static org.apache.maven.buildcache.xml.CacheConfigImpl.CACHE_SKIP;
 import static org.apache.maven.buildcache.xml.CacheConfigImpl.RESTORE_GENERATED_SOURCES_PROPERTY_NAME;
 import static org.apache.maven.buildcache.xml.CacheConfigImpl.RESTORE_ON_DISK_ARTIFACTS_PROPERTY_NAME;
+import static org.apache.maven.buildcache.xml.CacheConfigImpl.SKIP_SAVE;
 
 /**
  * MavenProjectInput
@@ -1012,4 +1013,15 @@ public static boolean isRestoreOnDiskArtifacts(MavenProject project) {
     public static boolean isCacheDisabled(MavenProject project) {
         return !Boolean.parseBoolean(project.getProperties().getProperty(CACHE_ENABLED_PROPERTY_NAME, "true"));
     }
+
+    /**
+     * Skip cache saving on a per-project level via a property.
+     * Defaults to false.
+     * {@code <maven.build.cache.skipSave>true<maven.build.cache.skipSave/>}
+     * @param project current project
+     * @return true if saving should be skipped for this project
+     */
+    public static boolean isSkipSave(MavenProject project) {
+        return Boolean.parseBoolean(project.getProperties().getProperty(SKIP_SAVE, "false"));
+    }
 }
diff --git a/src/site/markdown/parameters.md b/src/site/markdown/parameters.md
index 04b6ee0d..7be420b7 100644
--- a/src/site/markdown/parameters.md
+++ b/src/site/markdown/parameters.md
@@ -65,6 +65,7 @@ project properties:
 | `maven.build.cache.exclude.xxx`             | Additional <a href="build-cache-config.html#class_exclude">exclusion</a>. <br/><br/>Example :<br/>```<maven.build.cache.exclude.value.1>src/main/java/package-info.java<maven.build.cache.exclude.value.1>```<br/>```<maven.build.cache.exclude.value.2>src/main/resources<maven.build.cache.exclude.value.2>```<br/>```<maven.build.cache.exclude.glob.2>*.md<maven.build.cache.exclude.glob/2>```<br/>Produce two project exclusions :  <br/>```<exclude>s [...]
 | `maven.build.cache.processPlugins`          | Introspect plugins to find inputs or not. The default value is true.                                                                                                                                                                                                                                                                                                                                                                                         [...]
 | `maven.build.cache.skipCache`               | Skip looking up artifacts for a particular project in caches. The default value is false.                                                                                                                                                                                                                                                                                                                                                                    [...]
+| `maven.build.cache.skipSave`                | Skip writing build result in caches for a particular project. The default value is false.                                                                                                                                                                                                                                                                                                                                                                    [...]
 | `maven.build.cache.restoreGeneratedSources` | Restore generated sources and directly attached files in the corresponding project directories. The default value is true.                                                                                                                                                                                                                                                                                                                                   [...]
 | `maven.build.cache.restoreOnDiskArtifacts`  | Restore generated artifacts in the project build directory. The default value is true.                                                                                                                                                                                                                                                                                                                                                                       [...]
 
diff --git a/src/test/java/org/apache/maven/buildcache/its/PerModuleFlagsTest.java b/src/test/java/org/apache/maven/buildcache/its/PerModuleFlagsTest.java
index c5e2213f..ba8cc210 100644
--- a/src/test/java/org/apache/maven/buildcache/its/PerModuleFlagsTest.java
+++ b/src/test/java/org/apache/maven/buildcache/its/PerModuleFlagsTest.java
@@ -25,11 +25,16 @@
 import org.apache.maven.it.Verifier;
 import org.junit.jupiter.api.Test;
 
+import static org.apache.maven.buildcache.its.CacheITUtils.CACHE_SAVED;
+import static org.apache.maven.buildcache.util.LogFileUtils.findFirstLineContainingTextsInLogs;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
 @IntegrationTest("src/test/projects/per-module-flags")
 class PerModuleFlagsTest {
     private static final String PROJECT_NAME_MODULE1 = "org.apache.maven.caching.test.multimodule:module1";
     private static final String PROJECT_NAME_MODULE2 = "org.apache.maven.caching.test.multimodule:module2";
     private static final String PROJECT_NAME_MODULE3 = "org.apache.maven.caching.test.multimodule:module3";
+    private static final String PROJECT_NAME_MODULE4 = "org.apache.maven.caching.test.multimodule:module4";
 
     @Test
     void simple(Verifier verifier) throws VerificationException, IOException {
@@ -39,6 +44,9 @@ void simple(Verifier verifier) throws VerificationException, IOException {
         verifier.setLogFileName("../log-1.txt");
         verifier.executeGoal("verify");
         verifier.verifyErrorFreeLog();
+        assertNull(
+                findFirstLineContainingTextsInLogs(verifier, CACHE_SAVED, PROJECT_NAME_MODULE4),
+                "Module skipSave must prevent cache writes");
 
         // 2nd build
         verifier.setLogFileName("../log-2.txt");
@@ -48,5 +56,8 @@ void simple(Verifier verifier) throws VerificationException, IOException {
         verifier.verifyTextInLog("Project " + PROJECT_NAME_MODULE2
                 + " is marked as requiring force rebuild, will skip lookup in build cache");
         verifier.verifyTextInLog("Cache is explicitly disabled on project level for " + PROJECT_NAME_MODULE3);
+        assertNull(
+                findFirstLineContainingTextsInLogs(verifier, CACHE_SAVED, PROJECT_NAME_MODULE4),
+                "Module skipSave must prevent cache writes");
     }
 }
diff --git a/src/test/projects/per-module-flags/pom.xml b/src/test/projects/per-module-flags/module4/pom.xml
similarity index 56%
copy from src/test/projects/per-module-flags/pom.xml
copy to src/test/projects/per-module-flags/module4/pom.xml
index aeb47b45..a0dc16ca 100644
--- a/src/test/projects/per-module-flags/pom.xml
+++ b/src/test/projects/per-module-flags/module4/pom.xml
@@ -19,30 +19,19 @@
          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.caching.test.multimodule</groupId>
-    <artifactId>top</artifactId>
-    <version>0.0.1-SNAPSHOT</version>
-    <packaging>pom</packaging>
+    <artifactId>module4</artifactId>
+    <packaging>jar</packaging>
 
+    <parent>
+        <groupId>org.apache.maven.caching.test.multimodule</groupId>
+        <artifactId>top</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <!-- this subproject demonstrates usage of maven.build.cache.skipSave flag -->
     <properties>
-        <maven.compiler.source>1.8</maven.compiler.source>
-        <maven.compiler.target>1.8</maven.compiler.target>
+        <maven.build.cache.skipSave>true</maven.build.cache.skipSave>
     </properties>
 
-    <build>
-        <extensions>
-            <extension>
-                <groupId>org.apache.maven.extensions</groupId>
-                <artifactId>maven-build-cache-extension</artifactId>
-                <version>${projectVersion}</version>
-            </extension>
-        </extensions>
-    </build>
-
-    <modules>
-        <module>module1</module>
-        <module>module2</module>
-        <module>module3</module>
-    </modules>
-
 </project>
diff --git a/src/test/projects/per-module-flags/module4/src/main/java/org/apache/maven/buildcache/Test4.java b/src/test/projects/per-module-flags/module4/src/main/java/org/apache/maven/buildcache/Test4.java
new file mode 100644
index 00000000..03f66a82
--- /dev/null
+++ b/src/test/projects/per-module-flags/module4/src/main/java/org/apache/maven/buildcache/Test4.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+package org.apache.maven.buildcache;
+
+class Test
+{
+
+}
\ No newline at end of file
diff --git a/src/test/projects/per-module-flags/pom.xml b/src/test/projects/per-module-flags/pom.xml
index aeb47b45..59013a2b 100644
--- a/src/test/projects/per-module-flags/pom.xml
+++ b/src/test/projects/per-module-flags/pom.xml
@@ -43,6 +43,7 @@
         <module>module1</module>
         <module>module2</module>
         <module>module3</module>
+        <module>module4</module>
     </modules>
 
 </project>