有关详细信息,请参阅https://github.com/originalrusyn/java9_immutables
因此,以下配置适用于 sourceCompatibility = 1.8
p.package-info.java
@Value.Style(
defaults = @Value.Immutable(copy = false),
strictBuilder = true,
overshadowImplementation = true,
implementationNestedInBuilder = true
)
package p;
import org.immutables.value.Value;
构建.gradle
buildscript {
ext {
immutablesVersion = '2.5.6'
}
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.13"
}
}
group 'java9'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'net.ltgt.apt'
sourceCompatibility = 1.9
repositories {
mavenCentral()
}
sourceSets {
main
generated
test
}
compileJava {
generatedSourcesDestinationDir = "$projectDir/src/generated/java"
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
}
dependencies {
apt "org.immutables:value:${immutablesVersion}"
compileOnly "org.immutables:value:${immutablesVersion}:annotations"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
pbBjava
package p.b;
import org.immutables.value.Value;
@Value.Immutable
public interface B {
String getText();
}
为什么它会为 sourceCompatibility=1.9 生成 pbImmutableB.java 而不是 pbBBuilder.java?