Skip to content

Commit c6bb987

Browse files
committed
Handle configurations more lazily
This is in preparation for Gradle 8.14 which will no longer realize all configurations in the `base` plugin, allowing truly lazily-initialized configurations. This change should allow the javacConfiguration to only be initialized when JDK 8 is being used, and the various annotationProcessor configurations from source sets to only be initialized when needed, e.g. when a compilation tasks for that source set is run (it's likely that the `java` plugin doesn't yet take advantage of this new possibility itself though)
1 parent 0d4aec2 commit c6bb987

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/kotlin/net/ltgt/gradle/errorprone/ErrorPronePlugin.kt

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.gradle.api.Project
99
import org.gradle.api.file.FileCollection
1010
import org.gradle.api.plugins.ExtensionAware
1111
import org.gradle.api.plugins.JavaBasePlugin
12+
import org.gradle.api.provider.Provider
1213
import org.gradle.api.provider.ProviderFactory
1314
import org.gradle.api.tasks.Classpath
1415
import org.gradle.api.tasks.ClasspathNormalizer
@@ -74,16 +75,16 @@ class ErrorPronePlugin
7475
}
7576

7677
val errorproneConfiguration =
77-
project.configurations.create(CONFIGURATION_NAME) {
78+
project.configurations.register(CONFIGURATION_NAME) {
7879
description = "Error Prone dependencies, will be extended by all source sets' annotationProcessor configurations"
7980
isVisible = false
8081
isCanBeConsumed = false
8182
isCanBeResolved = false
8283

8384
exclude(group = "com.google.errorprone", module = "javac")
8485
}
85-
val javacConfiguration: FileCollection =
86-
project.configurations.create(JAVAC_CONFIGURATION_NAME) {
86+
val javacConfiguration: Provider<out FileCollection> =
87+
project.configurations.register(JAVAC_CONFIGURATION_NAME) {
8788
description = "Error Prone Javac dependencies, will only be used when using JDK 8 (i.e. not JDK 9 or superior)"
8889
isVisible = false
8990
isCanBeConsumed = false
@@ -131,7 +132,7 @@ class ErrorPronePlugin
131132

132133
project.plugins.withType<JavaBasePlugin> {
133134
project.extensions.getByName<SourceSetContainer>("sourceSets").configureEach {
134-
project.configurations[annotationProcessorConfigurationName].extendsFrom(errorproneConfiguration)
135+
project.configurations.named(annotationProcessorConfigurationName) { extendsFrom(errorproneConfiguration.get()) }
135136
project.tasks.named<JavaCompile>(compileJavaTaskName) {
136137
options.errorprone {
137138
isEnabled.convention(javaCompiler.map { it.metadata.languageVersion.asInt() >= 8 }.orElse(true))
@@ -146,7 +147,7 @@ class ErrorPronePlugin
146147
internal class ErrorProneJvmArgumentProvider(
147148
private val task: JavaCompile,
148149
private val errorproneOptions: ErrorProneOptions,
149-
private val javacConfiguration: FileCollection,
150+
private val javacConfiguration: Provider<out FileCollection>,
150151
) : CommandLineArgumentProvider,
151152
Named {
152153
@Internal override fun getName(): String = "errorprone"
@@ -171,7 +172,7 @@ internal class ErrorProneJvmArgumentProvider(
171172
when {
172173
!errorproneOptions.isEnabled.getOrElse(false) -> emptyList()
173174
compilerVersion == null -> emptyList()
174-
compilerVersion == JavaVersion.VERSION_1_8 -> listOf("-Xbootclasspath/p:${javacConfiguration.asPath}")
175+
compilerVersion == JavaVersion.VERSION_1_8 -> listOf("-Xbootclasspath/p:${javacConfiguration.get().asPath}")
175176
compilerVersion!! > JavaVersion.VERSION_1_8 -> ErrorPronePlugin.JVM_ARGS_STRONG_ENCAPSULATION
176177
else -> emptyList()
177178
}

0 commit comments

Comments
 (0)