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
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-2465.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: fix
fix:
description: Ensure that `baseline-immutables` configures immutables to work incrementally
when the immutables `annotationProcessor` dependency is not a direct dependency
(ie it is brought in transitively or by an `extendsFrom`).
links:
- https://github.com/palantir/gradle-baseline/pull/2465
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.util.Objects;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
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 @@ -74,12 +76,22 @@ private static boolean hasImmutablesProcessor(Project project, SourceSet sourceS
return project
.getConfigurations()
.getByName(sourceSet.getAnnotationProcessorConfigurationName())
.getDependencies()
.getIncoming()
.getResolutionResult()
.getAllComponents()
.stream()
.anyMatch(BaselineImmutables::isImmutablesValue);
}

private static boolean isImmutablesValue(Dependency dep) {
return Objects.equals(dep.getGroup(), "org.immutables") && Objects.equals(dep.getName(), "value");
private static boolean isImmutablesValue(ResolvedComponentResult component) {
ComponentIdentifier id = component.getId();

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

ModuleComponentIdentifier moduleId = (ModuleComponentIdentifier) id;

return Objects.equals(moduleId.getGroup(), "org.immutables") && Objects.equals(moduleId.getModule(), "value");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,50 @@ class BaselineImmutablesTest extends IntegrationSpec {
where:
javaVersion << ImmutableList.of(11, 17)
}

def 'handles an annotationProcesor source set extending from another one'() {
buildFile << """
apply plugin: 'com.palantir.baseline-immutables'
apply plugin: 'java-library'

repositories {
mavenCentral()
}

dependencies {
annotationProcessor '$IMMUTABLES'
compileOnly '$IMMUTABLES_ANNOTATIONS'
}

configurations {
testAnnotationProcessor.extendsFrom annotationProcessor
testCompileOnly.extendsFrom compileOnly
}

tasks.withType(JavaCompile) { javaCompile ->
doFirst {
logger.lifecycle "\${javaCompile.name}: \${javaCompile.options.allCompilerArgs}"
}
}
""".stripIndent(true)

def testJava = 'src/test/java'

// language=java
writeJavaSourceFile '''
package test;
import org.immutables.value.Value;
@Value.Immutable
public interface Test {
int item();
}
'''.stripIndent(true), testJava

when:
def stdout = runTasksSuccessfully('compileTestJava').standardOutput
println stdout

then:
stdout.contains('compileTestJava: [-Aimmutables.gradle.incremental]')
}
}