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-2406.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: baseline-immutables adds required exports to the java compiler for
compatibility with jdk-17+
links:
- https://github.com/palantir/gradle-baseline/pull/2406
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.palantir.baseline.plugins;

import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.Objects;
import org.gradle.api.Plugin;
Expand All @@ -28,6 +29,11 @@

public final class BaselineImmutables implements Plugin<Project> {

private static final ImmutableList<String> GRADLE_INCREMENTAL = ImmutableList.of("-Aimmutables.gradle.incremental");
// See https://github.com/immutables/immutables/issues/1379
private static final ImmutableList<String> EXPORTS =
ImmutableList.of("--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED");

@Override
public void apply(Project project) {
project.getPluginManager().withPlugin("java", unused -> {
Expand All @@ -42,11 +48,21 @@ public void apply(Project project) {
.add(new CommandLineArgumentProvider() {
@Override
public Iterable<String> asArguments() {
if (hasImmutablesProcessor(project, sourceSet)) {
return Collections.singletonList("-Aimmutables.gradle.incremental");
}

return Collections.emptyList();
return hasImmutablesProcessor(project, sourceSet)
? GRADLE_INCREMENTAL
: Collections.emptyList();
}
});
javaCompileTask
.getOptions()
.getForkOptions()
.getJvmArgumentProviders()
.add(new CommandLineArgumentProvider() {
@Override
public Iterable<String> asArguments() {
return hasImmutablesProcessor(project, sourceSet)
? EXPORTS
: Collections.emptyList();
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package com.palantir.baseline.plugins

import com.google.common.collect.ImmutableList
import nebula.test.IntegrationSpec
import nebula.test.functional.ExecutionResult

class BaselineImmutablesTest extends IntegrationSpec {
private static final String IMMUTABLES = 'org.immutables:value:2.8.8'
private static final String IMMUTABLES_ANNOTATIONS = 'org.immutables:value:2.8.8:annotations'
Comment on lines 24 to +25
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious when we bump these to test compatibility (e.g. latest is 2.9.2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran tests with both versions, 2.9.2 seems solid where I’ve tried it, but this week has been support-heavy so I’d prefer not to tempt fate quite yet :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Definitely understand


def 'inserts incremental compilation args into source sets that have immutables'() {
buildFile << """
Expand Down Expand Up @@ -79,4 +82,50 @@ class BaselineImmutablesTest extends IntegrationSpec {
stdout.contains 'compileDoesNotHaveImmutablesJava: []'
stdout.contains 'compileHasImmutablesAddedInAfterEvaluateJava: [-Aimmutables.gradle.incremental]'
}

def 'Compatible with java #javaVersion'() {
when:
buildFile << """
apply plugin: 'com.palantir.baseline-java-versions'
apply plugin: 'com.palantir.baseline-immutables'
apply plugin: 'java-library'
repositories {
mavenCentral()
}
tasks.withType(JavaCompile).configureEach({
options.compilerArgs += ['-Werror']
})
javaVersions {
libraryTarget = $javaVersion
}
dependencies {
annotationProcessor '$IMMUTABLES'
compileOnly '$IMMUTABLES_ANNOTATIONS'
}
""".stripIndent()
writeJavaSourceFile("""
package com.palantir.one;
import com.palantir.two.ImmutableTwo;
import org.immutables.value.Value;
@Value.Immutable
public interface One {
ImmutableTwo two();
}
""".stripIndent())
writeJavaSourceFile("""
package com.palantir.two;
import org.immutables.value.Value;
@Value.Immutable
public interface Two {
String value();
}
""".stripIndent())
then:
ExecutionResult result = runTasks('compileJava')
println(result.standardError)
result.success

where:
javaVersion << ImmutableList.of(11, 17)
}
}