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/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/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 + `` — full re-scan from root activates profile, discovers B with matching effective model | `` | ✅ | `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 | `` (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 | `` | | `maven.build.cache.processPlugins` | `true` | boolean | — (POM property per-project) | | `maven.build.cache.input.glob` | — | 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 e7a7a8d2..c7e01f18 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 @@ -994,4 +995,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 true} + * @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 c0c62e56..40340ae9 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 exclusion.

Example :
```src/main/java/package-info.java```
```src/main/resources```
```*.md```
Produce two project exclusions :
```src/main/java/package-info.java```
```src/main/resources``` | | `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/module4/pom.xml b/src/test/projects/per-module-flags/module4/pom.xml new file mode 100644 index 00000000..a0dc16ca --- /dev/null +++ b/src/test/projects/per-module-flags/module4/pom.xml @@ -0,0 +1,37 @@ + + + + 4.0.0 + module4 + jar + + + org.apache.maven.caching.test.multimodule + top + 0.0.1-SNAPSHOT + ../pom.xml + + + + + true + + + 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 @@ module1 module2 module3 + module4