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