Skip to content

Commit

Permalink
Don't reprocess aggregated types when there's nothing to compile
Browse files Browse the repository at this point in the history
Fixes micronaut-projects/micronaut-core#6536

Signed-off-by: Stefan Oehme <st.oehme@gmail.com>
  • Loading branch information
oehme committed Nov 22, 2021
1 parent 0eb70ae commit fdb1e20
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Expand Up @@ -21,6 +21,7 @@ import org.gradle.integtests.fixtures.CompilationOutputsFixture
import org.gradle.language.fixtures.AnnotationProcessorFixture
import org.gradle.language.fixtures.CompileJavaBuildOperationsFixture
import org.gradle.test.fixtures.file.TestFile
import org.intellij.lang.annotations.Language

abstract class AbstractIncrementalAnnotationProcessingIntegrationTest extends AbstractIntegrationSpec {

Expand Down Expand Up @@ -53,6 +54,9 @@ abstract class AbstractIncrementalAnnotationProcessingIntegrationTest extends Ab
dependencies {
compileOnly project(":annotation")
annotationProcessor project(":processor")
testCompileOnly project(":annotation")
testAnnotationProcessor project(":processor")
}
"""

Expand All @@ -70,7 +74,7 @@ abstract class AbstractIncrementalAnnotationProcessingIntegrationTest extends Ab
processor.writeAnnotationProcessorTo(processorProjectDir)
}

protected final File java(String... classBodies) {
protected final File java(@Language("java") String... classBodies) {
javaInPackage('', classBodies)
}

Expand Down
Expand Up @@ -436,6 +436,23 @@ class AggregatingIncrementalAnnotationProcessingIntegrationTest extends Abstract
succeeds "compileJava"
}
@Issue("https://https://github.com/micronaut-projects/micronaut-core/issues/6536")
def "does not reprocess if nothing in the current sourceSet changed"() {
given:
withProcessor(new AnnotatedGeneratedClassProcessorFixture())
javaTestSourceFile "@Bean class Test {}"
outputs.snapshot { succeeds "compileTestJava" }
when:
java "class Unrelated {}"
then:
succeeds "compileTestJava"
and:
outputs.recompiledClasses("Unrelated")
}
private boolean serviceRegistryReferences(String... services) {
def registry = file("build/classes/java/main/ServiceRegistryResource.txt").text
services.every() {
Expand Down
Expand Up @@ -157,6 +157,9 @@ private DependentsSet findDirectDependents(String className) {
* - the originating types of generated classes that need to be recompiled, since they wouldn't exist if the originating type is not reprocessed
*/
public Set<String> getTypesToReprocess(Set<String> compiledClasses) {
if (compiledClasses.isEmpty()) {
return Collections.emptySet();
}
Set<String> typesToReprocess = new HashSet<>(annotationProcessingData.getAggregatedTypes());
for (Map.Entry<String, Set<String>> entry : annotationProcessingData.getGeneratedTypesByOrigin().entrySet()) {
if (entry.getValue().stream().anyMatch(compiledClasses::contains)) {
Expand Down

0 comments on commit fdb1e20

Please sign in to comment.