You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "tfactor2 (via GitHub)" <gi...@apache.org> on 2026/06/24 20:04:09 UTC
[PR] Fix compile cache artifact escalation [maven-build-cache-extension]
tfactor2 opened a new pull request, #498:
URL: https://github.com/apache/maven-build-cache-extension/pull/498
## Summary
Fix compile-only cache entries so `target/classes` is cached as an attached output archive instead of being serialized as the Maven project's main artifact.
This prevents a `mvn compile` cache hit from poisoning later `mvn package`/`mvn install` runs with a directory-backed main artifact while keeping compile output caching enabled for jar modules. The change also keeps a compatibility guard for legacy cache entries that already contain a directory-backed main artifact.
A zipped standalone reproducer is included under `src/test/projects/maven-cache-install-after-compile-repro.zip`.
## Tests
- `mvn -q -Drat.skip=true test`
- Targeted smoke ITs for `compile -> package` and `compile -> install`
- Standalone reproducer against the built snapshot
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix compile cache artifact escalation [maven-build-cache-extension]
Posted by "tfactor2 (via GitHub)" <gi...@apache.org>.
tfactor2 commented on code in PR #498:
URL: https://github.com/apache/maven-build-cache-extension/pull/498#discussion_r3470097609
##########
src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java:
##########
@@ -677,50 +675,20 @@ public void save(
}
/**
- * Saves a project artifact to cache, handling both regular files and directory artifacts.
- * Directory artifacts (e.g., target/classes from compile-only builds) are zipped before saving
- * since Files.copy() cannot handle directories.
+ * Saves a project artifact to cache.
*/
private void saveProjectArtifact(
CacheResult cacheResult, org.apache.maven.artifact.Artifact projectArtifact, MavenProject project)
throws IOException {
File originalFile = projectArtifact.getFile();
try {
- if (originalFile.isDirectory()) {
- saveDirectoryArtifact(cacheResult, projectArtifact, project, originalFile);
- } else {
- // Regular file (JAR/WAR) - save directly
- localCache.saveArtifactFile(cacheResult, projectArtifact);
- }
+ localCache.saveArtifactFile(cacheResult, projectArtifact);
} finally {
// Restore original file reference in case it was temporarily changed
projectArtifact.setFile(originalFile);
}
}
- /**
- * Saves a directory artifact by zipping it first, then saving the zip to cache.
- */
- private void saveDirectoryArtifact(
Review Comment:
[explanation] #Why `saveDirectoryArtifact(...)` is removed:
The method made a directory-backed Maven project artifact saveable by zipping it and storing it through the main artifact path. That preserved the invalid metadata shape that caused #449: `target/classes` is a compile output directory, not the project's packaged main artifact.
With this change, `saveProjectArtifact(...)` only saves regular files produced by package-or-later mojos. Compile outputs are still cached, but through `attachCompileOutputs(...)` / attached output archives, so jar modules keep compile-cache benefits without letting `target/classes` poison later `package` or `install` executions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix compile cache artifact escalation [maven-build-cache-extension]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #498:
URL: https://github.com/apache/maven-build-cache-extension/pull/498#discussion_r3469961032
##########
src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java:
##########
@@ -1323,13 +1335,15 @@ private Set<Path> collectCachedArtifactPaths(MavenProject project) {
final org.apache.maven.artifact.Artifact projectArtifact = project.getArtifact();
final Path targetDir = Paths.get(project.getBuild().getDirectory());
- // 1. Main project artifact (JAR file or target/classes directory)
- if (projectArtifact.getFile() != null && projectArtifact.getFile().exists()) {
+ // 1. Main project artifact (JAR/WAR/etc. file)
+ if (projectArtifact.getFile() != null && projectArtifact.getFile().isFile()) {
paths.add(projectArtifact.getFile().toPath());
}
- // 2. Attached outputs from configuration (if cacheCompile enabled)
+ // 2. Compile outputs and configured attached outputs (if cacheCompile enabled)
if (cacheConfig.isCacheCompile()) {
+ addExistingOutputPath(paths, project.getBuild().getOutputDirectory());
+ addExistingOutputPath(paths, project.getBuild().getTestOutputDirectory());
List<DirName> attachedDirs = cacheConfig.getAttachedOutputs();
Review Comment:
collectCachedArtifactPaths() now adds build output directories via Paths.get(outputDirectory) without validating they are within the project. If outputDirectory is configured outside the project (or resolves outside due to relative paths), stagePreExistingArtifacts() will later throw on multimoduleRoot.relativize(path) or could move arbitrary filesystem paths into the staging dir. Align this with attachOutputs()/attachCompileOutput() by discarding output paths that are outside the project (and do the same for configured attached outputs).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix compile cache artifact escalation [maven-build-cache-extension]
Posted by "tfactor2 (via GitHub)" <gi...@apache.org>.
tfactor2 commented on code in PR #498:
URL: https://github.com/apache/maven-build-cache-extension/pull/498#discussion_r3470146933
##########
src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java:
##########
@@ -1323,13 +1335,15 @@ private Set<Path> collectCachedArtifactPaths(MavenProject project) {
final org.apache.maven.artifact.Artifact projectArtifact = project.getArtifact();
final Path targetDir = Paths.get(project.getBuild().getDirectory());
- // 1. Main project artifact (JAR file or target/classes directory)
- if (projectArtifact.getFile() != null && projectArtifact.getFile().exists()) {
+ // 1. Main project artifact (JAR/WAR/etc. file)
+ if (projectArtifact.getFile() != null && projectArtifact.getFile().isFile()) {
paths.add(projectArtifact.getFile().toPath());
}
- // 2. Attached outputs from configuration (if cacheCompile enabled)
+ // 2. Compile outputs and configured attached outputs (if cacheCompile enabled)
if (cacheConfig.isCacheCompile()) {
+ addExistingOutputPath(paths, project.getBuild().getOutputDirectory());
+ addExistingOutputPath(paths, project.getBuild().getTestOutputDirectory());
List<DirName> attachedDirs = cacheConfig.getAttachedOutputs();
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix compile cache artifact escalation [maven-build-cache-extension]
Posted by "tfactor2 (via GitHub)" <gi...@apache.org>.
tfactor2 commented on PR #498:
URL: https://github.com/apache/maven-build-cache-extension/pull/498#issuecomment-4793404626
Addressed the path-safety review feedback in the latest push (`b534e3c`):
- `collectCachedArtifactPaths()` now uses the same project-contained path validation for compile output directories and configured attached outputs.
- Relative paths are normalized against the project base directory before collection, and outside-project candidates are discarded.
- `stagePreExistingArtifacts()` also guards against moving any candidate outside the reactor root.
- Added a regression test that verifies outside compile output and attached output directories are not collected for staging.
Also removed the reproducer zip from the source diff; it should live on the GitHub issue rather than in the repository.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix compile cache artifact escalation [maven-build-cache-extension]
Posted by "tfactor2 (via GitHub)" <gi...@apache.org>.
tfactor2 commented on PR #498:
URL: https://github.com/apache/maven-build-cache-extension/pull/498#issuecomment-4793253365
Why `saveDirectoryArtifact(...)` is removed:
The method made a directory-backed Maven project artifact saveable by zipping it and storing it through the main artifact path. That preserved the invalid metadata shape that caused #449: `target/classes` is a compile output directory, not the project's packaged main artifact.
With this change, `saveProjectArtifact(...)` only saves regular files produced by package-or-later mojos. Compile outputs are still cached, but through `attachCompileOutputs(...)` / attached output archives, so jar modules keep compile-cache benefits without letting `target/classes` poison later `package` or `install` executions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix compile cache artifact escalation [maven-build-cache-extension]
Posted by "cstamas (via GitHub)" <gi...@apache.org>.
cstamas commented on PR #498:
URL: https://github.com/apache/maven-build-cache-extension/pull/498#issuecomment-5038464243
Please rebase against latest master.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org