Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions documentation/extension-features-test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down Expand Up @@ -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` |
Expand Down Expand Up @@ -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 | ✅ |
Expand Down Expand Up @@ -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) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <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"));
}
}
1 change: 1 addition & 0 deletions src/site/markdown/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>src/main/java/package-info.java</exclude>```<br/>```<exclude glob="*.md">src/main/resources</exclude>``` |
| `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. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
Expand All @@ -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");
}
}
37 changes: 37 additions & 0 deletions src/test/projects/per-module-flags/module4/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--

Copyright 2021 the original author or authors.

Licensed 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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<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.build.cache.skipSave>true</maven.build.cache.skipSave>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -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
{

}
1 change: 1 addition & 0 deletions src/test/projects/per-module-flags/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<module>module1</module>
<module>module2</module>
<module>module3</module>
<module>module4</module>
</modules>

</project>