diff --git a/src/main/java/org/apache/maven/buildcache/DefaultProjectInputCalculator.java b/src/main/java/org/apache/maven/buildcache/DefaultProjectInputCalculator.java index 30bd052b..2a1217fd 100644 --- a/src/main/java/org/apache/maven/buildcache/DefaultProjectInputCalculator.java +++ b/src/main/java/org/apache/maven/buildcache/DefaultProjectInputCalculator.java @@ -72,8 +72,11 @@ public DefaultProjectInputCalculator( @Override public ProjectsInputInfo calculateInput(MavenProject project) { - LOGGER.info("Going to calculate checksum for project [groupId=" + project.getGroupId() + ", artifactId=" - + project.getArtifactId() + "]"); + LOGGER.info( + "Going to calculate checksum for project [groupId={}, artifactId={}, version={}]", + project.getGroupId(), + project.getArtifactId(), + project.getVersion()); String key = BuilderCommon.getKey(project); // NOTE: Do not use ConcurrentHashMap.computeIfAbsent() here because of recursive calls 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 8dacf334..4b75dd45 100644 --- a/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java +++ b/src/main/java/org/apache/maven/buildcache/checksum/MavenProjectInput.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.nio.file.DirectoryStream; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -178,8 +179,8 @@ public ProjectsInputInfo calculateChecksum() throws IOException { final long t1 = System.currentTimeMillis(); - // hash items: effective pom + input files + dependencies - final int count = 1 + inputFiles.size() + dependenciesChecksum.size(); + // hash items: effective pom + version + input files + dependencies + final int count = 2 + inputFiles.size() + dependenciesChecksum.size(); final List items = new ArrayList<>(count); final HashChecksum checksum = config.getHashFactory().createChecksum(count); @@ -189,6 +190,14 @@ public ProjectsInputInfo calculateChecksum() throws IOException { remoteCache.findBaselineBuild(project).map(b -> b.getDto().getProjectsInputInfo()); } + DigestItem projectVersion = new DigestItem(); + projectVersion.setType("version"); + projectVersion.setIsText("yes"); + projectVersion.setValue(project.getVersion()); + items.add(projectVersion); + + checksum.update(project.getVersion().getBytes(StandardCharsets.UTF_8)); + DigestItem effectivePomChecksum = DigestUtils.pom(checksum, effectivePom); items.add(effectivePomChecksum); final boolean compareWithBaseline = config.isBaselineDiffEnabled() && baselineHolder.isPresent(); @@ -227,9 +236,12 @@ public ProjectsInputInfo calculateChecksum() throws IOException { final long t2 = System.currentTimeMillis(); - for (DigestItem item : projectsInputInfoType.getItems()) { - LOGGER.debug("Hash calculated, item: {}, hash: {}", item.getType(), item.getHash()); + if (LOGGER.isDebugEnabled()) { + for (DigestItem item : projectsInputInfoType.getItems()) { + LOGGER.debug("Hash calculated, item: {}, hash: {}", item.getType(), item.getHash()); + } } + LOGGER.info( "Project inputs calculated in {} ms. {} checksum [{}] calculated in {} ms.", t1 - t0, diff --git a/src/test/java/org/apache/maven/buildcache/its/CoreExtensionTest.java b/src/test/java/org/apache/maven/buildcache/its/CoreExtensionTest.java index a788da44..cdd5b832 100644 --- a/src/test/java/org/apache/maven/buildcache/its/CoreExtensionTest.java +++ b/src/test/java/org/apache/maven/buildcache/its/CoreExtensionTest.java @@ -41,4 +41,37 @@ void simple(Verifier verifier) throws VerificationException { verifier.verifyErrorFreeLog(); verifier.verifyTextInLog("Found cached build, restoring " + PROJECT_NAME + " from cache"); } + + @Test + void simple_build_change_version_build_install_again(Verifier verifier) throws VerificationException { + verifier.setAutoclean(false); + + verifier.setLogFileName("../log-1.txt"); + verifier.executeGoal("install"); + verifier.verifyErrorFreeLog(); + verifier.verifyArtifactPresent("org.apache.maven.caching.test.simple", "simple", "0.0.1-SNAPSHOT", "jar"); + + verifier.setLogFileName("../log-2.txt"); + verifier.executeGoal("install"); + verifier.verifyErrorFreeLog(); + verifier.verifyTextInLog("Found cached build, restoring " + PROJECT_NAME + " from cache"); + + verifier.setLogFileName("../log-3.txt"); + verifier.getCliOptions().clear(); + verifier.addCliOption("-DoldVersion=0.0.1-SNAPSHOT"); + verifier.addCliOption("-DnewVersion=0.0.2-SNAPSHOT"); + verifier.executeGoal("versions:set"); + verifier.verifyErrorFreeLog(); + + verifier.getCliOptions().clear(); + verifier.setLogFileName("../log-4.txt"); + verifier.executeGoal("install"); + verifier.verifyErrorFreeLog(); + verifier.verifyArtifactPresent("org.apache.maven.caching.test.simple", "simple", "0.0.2-SNAPSHOT", "jar"); + + verifier.setLogFileName("../log-5.txt"); + verifier.executeGoal("install"); + verifier.verifyErrorFreeLog(); + verifier.verifyTextInLog("Found cached build, restoring " + PROJECT_NAME + " from cache"); + } } diff --git a/src/test/projects/core-extension/pom.xml b/src/test/projects/core-extension/pom.xml index cd309b79..6aa09789 100644 --- a/src/test/projects/core-extension/pom.xml +++ b/src/test/projects/core-extension/pom.xml @@ -29,4 +29,20 @@ 1.8 + + + + + + org.codehaus.mojo + versions-maven-plugin + 2.16.0 + + false + + + + + + \ No newline at end of file