Maven Build Cache Extension repeating cached steps

  Kiến thức lập trình

I’m trying to use the Maven Build Cache Extension to cache the results from one Maven command for use in another. For example:

./mvnw clean compile
./mvnw test          # Should use cached compile
./mvnw package       # Should use cached compile and test
./mvnw verify        # Should use cached compile, test, and package
./mvnw install       # Should use cached compile, test, package, and verify
./mvnw deploy        # Should use cached compile, test, package, verify, and install

However, when I run the commands consecutively like this, I notice that it resumes where the previous command left off to start out with, but then it goes back and runs the Maven lifecycle from the beginning. Consider this output of ./mvnw install after running ./mvnw verify. It uses the previously cached steps and jumps straight to the install, as one would expect it to, but after that install finishes, it starts the Maven lifecycle over again from the compilation phase.

[INFO] --------------< com.example:foo-core >---------------
[INFO] Building foo-core 5.0.0-SNAPSHOT                               [2/27]
[INFO]   from core/foo-core/pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] Going to calculate checksum for project [groupId=com.example.foo, artifactId=foo-core]
[INFO] Scanning plugins configurations to find input files. Probing is enabled, values will be checked for presence in file system
[INFO] Found 421 input files. Project dir processing: 42, plugins: 6 millis
[INFO] Project inputs calculated in 77 ms. XX checksum [0a64c649f3c93a45] calculated in 151 ms.
[INFO] Attempting to restore project com.example.foo:foo-core from build cache
[INFO] Local build found by checksum 0a64c649f3c93a45
[INFO] Found cached build, restoring com.example.foo:foo-core from cache by checksum 0a64c649f3c93a45
[INFO] Project com.example.foo:foo-core restored partially. Highest cached goal: verify, requested: install
[INFO] Skipping plugin execution (cached): resources:resources
[INFO] Skipping plugin execution (cached): flatten:flatten
[INFO] Skipping plugin execution (cached): compiler:compile
[INFO] Skipping plugin execution (cached): resources:testResources
[INFO] Skipping plugin execution (cached): compiler:testCompile
[INFO] Skipping plugin execution (cached): surefire:test
[INFO] Skipping plugin execution (cached): jar:jar
[INFO] Skipping plugin execution (cached): source:jar-no-fork
[INFO]
[INFO] --- install:3.1.2:install (default-install) @ foo-core ---
[INFO] Installing /home/me/sources/foo-5.0.x/core/foo-core/pom.xml to /home/me/.m2/repository/com/example/foo/foo-core/5.0.0-SNAPSHOT/foo-core-5.0.0-SNAPSHOT.pom
[INFO] Installing /home/me/.m2/build-cache/v1/com.example.foo/foo-core/0a64c649f3c93a45/local/foo-core.jar to /home/me/.m2/repository/com/example/foo/foo-core/5.0.0-SNAPSHOT/foo-core-5.0.0-SNAPSHOT.jar
[INFO] Installing /home/me/.m2/build-cache/v1/com.example.foo/foo-core/0a64c649f3c93a45/local/foo-core-sources.jar to /home/me/.m2/repository/com/example/foo/foo-core/5.0.0-SNAPSHOT/foo-core-5.0.0-SNAPSHOT-sources.jar
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ foo-core ---
[INFO] Copying 1 resource from src/main/java/com/example/foo/core/spring/schema to target/classes/com/example/foo/core/spring/schema
[INFO] Copying 8 resources from src/main/resources to target/classes
[INFO]
[INFO] --- flatten:1.6.0:flatten (flatten) @ foo-core ---
[INFO] Generating flattened POM of project com.example.foo:foo-core:jar:5.0.0-SNAPSHOT...
[INFO]
[INFO] --- compiler:3.13.0:compile (default-compile) @ foo-core ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 354 source files with javac [debug deprecation target 17] to target/classes

This behavior is not limited to this example either; I see the same behavior no matter which Maven command I pass to it: test, package, verify, install, or deploy.

Is this something that the Maven Build Cache Extension supports, or am I misunderstanding how it is meant to be used? If it does support this usage, is this a bug or is it something I’m doing incorrectly? For reference, I’m using Java 17, Maven v3.9.6 (via the Maven Wrapper Script), Maven Build Cache Extension v1.1.0 and a multi-module project structured using Maven CI-Friendly Versions.

LEAVE A COMMENT