cowwoc opened a new issue, #393:
URL: https://github.com/apache/maven-build-cache-extension/issues/393

   ### Affected version
   
   1.2.0
   
   ### Bug description
   
    ### Environment
     - **Maven Build Cache Extension**: v1.2.0
     - **Maven**: 3.9.9
     - **Java**: 25
     - **Project Type**: Multi-module JPMS (Java Platform Module System) project
   
     ### Problem Description
   
     When running `./mvnw clean compile` followed by `./mvnw verify`, the build 
fails with "module not found" errors despite the cache indicating a hit.
   
     ### Root Cause
   
     The Maven Build Cache Extension creates incomplete cache entries when 
builds terminate at the `compile` phase:
   
     1. **Compile-only build** (`./mvnw clean compile`):
        - Saves build metadata to cache
        - **Does NOT save** `attachedOutputs` (classes directory)
        - Creates cache entry with `<final>false</final>` in buildinfo.xml
        - Cache directory contains only `buildinfo.xml`, no ZIP files for 
classes
   
     2. **Subsequent verify build** (`./mvnw verify`):
        - Finds cached entry by checksum
        - Attempts to restore from cache
        - **No classes to restore** (attachedOutputs were never saved)
        - Skips compilation (thinks it's cached)
        - Results in "module not found" errors
   
     ### Steps to Reproduce
   
     ```bash
     # Step 1: Clean and run compile-only build
     ./mvnw clean compile
   
     # Step 2: Examine cache - only buildinfo.xml exists, no class ZIPs
     ls ~/.m2/build-cache/v1.1/groupId/artifactId/checksum/local/
     # Output: buildinfo.xml only
   
     # Step 3: Run verify build
     ./mvnw clean verify
     # Result: Compilation errors - "module not found: module.name"
   
     Expected Behavior
   
     One of the following should occur:
   
     Option 1 (Preferred): Don't cache incomplete builds
     - compile-only builds should not create cache entries
     - Only package or higher phases should save to cache
   
     Option 2: Don't restore from incomplete cache
     - Mark <final>false</final> entries as non-restorable
     - Force rebuild when requested phase is higher than cached phase
   
     Option 3: Save minimal attachedOutputs for all phases
     - Even compile-only builds should save the classes directory
     - Ensure attachedOutputs configuration applies to all cached phases
   
     Current Workaround
   
     # Clear stale cache entries
     rm -rf ~/.m2/build-cache/
   
     # Always use verify or package (not compile)
     ./mvnw clean verify
   
     Cache Configuration
   
     .mvn/maven-build-cache-config.xml:
     <attachedOutputs>
       <dirNames>
         <dirName>classes</dirName>
         <dirName>test-classes</dirName>
         <dirName>maven-status</dirName>
       </dirNames>
     </attachedOutputs>
   
     This configuration works correctly for package/verify builds but is 
ignored for compile-only builds.
   
     Observed Behavior
   
     - With package/verify: ✅ Works correctly
       - Saves classes as artifactId-mvn-cache-ext-extra-output-N.zip
       - Restores both JAR and classes directory
       - Full module resolution works
     - With compile only: ❌ Incomplete caching
       - buildinfo.xml shows <final>false</final>
       - No attachedOutputs ZIP files created
       - Cache restoration fails silently
   
     Impact
   
     This affects JPMS projects where module-info.class must be present in 
target/classes for module resolution. The incomplete cache restoration bypasses 
compilation but doesn't provide the required class files.
   
     Related Issues
   
     This may be related to:
     - MBUILDCACHE-45: "Compiled classes are not copied/restored to target"
     - The documented behavior that "cache automatically kicks in on every 
package or higher phase"
   
     Suggested Fix
   
     The extension should either:
     1. Not create cache entries for builds that don't reach package phase, OR
     2. Save attachedOutputs for all cached phases (including compile), OR
     3. Refuse to restore from <final>false</final> entries when a higher phase 
is requested


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to