Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-2717.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Ignore `org.immutables:value::annotations` when deciding to add the
annotation processor arg required by immutables to run incrementally.
links:
- https://github.com/palantir/gradle-baseline/pull/2717
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.util.Objects;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.artifacts.result.ResolvedComponentResult;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.compile.JavaCompile;
Expand Down Expand Up @@ -76,22 +76,27 @@ private static boolean hasImmutablesProcessor(Project project, SourceSet sourceS
return project
.getConfigurations()
.getByName(sourceSet.getAnnotationProcessorConfigurationName())
.getIncoming()
.getResolutionResult()
.getAllComponents()
.getResolvedConfiguration()
.getResolvedArtifacts()
.stream()
.anyMatch(BaselineImmutables::isImmutablesValue);
}

private static boolean isImmutablesValue(ResolvedComponentResult component) {
ComponentIdentifier id = component.getId();
private static boolean isImmutablesValue(ResolvedArtifact resolvedArtifact) {
ComponentIdentifier id = resolvedArtifact.getId().getComponentIdentifier();

if (!(id instanceof ModuleComponentIdentifier)) {
return false;
}

ModuleComponentIdentifier moduleId = (ModuleComponentIdentifier) id;

return Objects.equals(moduleId.getGroup(), "org.immutables") && Objects.equals(moduleId.getModule(), "value");
// The actual annotation processor jar has no classifier, we must make sure not to match on the
// `annotations` jar which has the `annotations` classifier
boolean noClassifier = resolvedArtifact.getClassifier() == null;

return Objects.equals(moduleId.getGroup(), "org.immutables")
&& Objects.equals(moduleId.getModule(), "value")
&& noClassifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class BaselineImmutablesTest extends IntegrationSpec {
hasImmutables
doesNotHaveImmutables
hasImmutablesAddedInAfterEvaluate
onlyHasImmutablesAnnotations
}

afterEvaluate {
Expand All @@ -53,6 +54,8 @@ class BaselineImmutablesTest extends IntegrationSpec {
annotationProcessor '$IMMUTABLES'

hasImmutablesAnnotationProcessor '$IMMUTABLES'

onlyHasImmutablesAnnotationsAnnotationProcessor '$IMMUTABLES_ANNOTATIONS'
}

task compileAll
Expand All @@ -66,7 +69,7 @@ class BaselineImmutablesTest extends IntegrationSpec {
}
""".stripIndent()

['main', 'hasImmutables', 'doesNotHaveImmutables', 'hasImmutablesAddedInAfterEvaluate'].each {
['main', 'hasImmutables', 'doesNotHaveImmutables', 'hasImmutablesAddedInAfterEvaluate', 'onlyHasImmutablesAnnotations'].each {
writeJavaSourceFile '''
public class Foo {}
'''.stripIndent(), "src/$it/java"
Expand All @@ -81,6 +84,7 @@ class BaselineImmutablesTest extends IntegrationSpec {
stdout.contains 'compileHasImmutablesJava: [-Aimmutables.gradle.incremental]'
stdout.contains 'compileDoesNotHaveImmutablesJava: []'
stdout.contains 'compileHasImmutablesAddedInAfterEvaluateJava: [-Aimmutables.gradle.incremental]'
stdout.contains 'compileOnlyHasImmutablesAnnotationsJava: []'
}

def 'Compatible with java #javaVersion'() {
Expand Down