From c85b30392ea946eacd987ebade4d4bb0e4552a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9da=20Housni=20Alaoui?= Date: Thu, 22 Aug 2024 00:57:44 +0200 Subject: [PATCH] Missing compile source roots matching 'generated-sources' and 'generated-test-sources' when compiler is skipped --- .../apache/maven/buildcache/CacheControllerImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java b/src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java index 6cc644f9..d78adbdc 100644 --- a/src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java +++ b/src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java @@ -892,6 +892,18 @@ private void restoreGeneratedSources(Artifact artifact, Path artifactFilePath, M Files.createDirectories(outputDir); } CacheUtils.unzip(artifactFilePath, outputDir); + OutputType outputType = OutputType.fromClassifier(artifact.getClassifier()); + if (outputType != OutputType.GENERATED_SOURCE) { + return; + } + Path targetDir = Paths.get(project.getBuild().getDirectory()); + if (outputDir.equals(targetDir.resolve("generated-sources")) + && !project.getCompileSourceRoots().contains(outputDir.toString())) { + project.addCompileSourceRoot(outputDir.toString()); + } else if (outputDir.equals(targetDir.resolve("generated-test-sources")) + && !project.getTestCompileSourceRoots().contains(outputDir.toString())) { + project.addTestCompileSourceRoot(outputDir.toString()); + } } // TODO: move to config