Skip to content

Commit

Permalink
Replace usages of findProperty
Browse files Browse the repository at this point in the history
`findProperty` is not compatible with project isolation. The new
`providers.gradleProperty` is however.

This partially fixes #1752
  • Loading branch information
ansman committed Aug 18, 2024
1 parent 3ff526d commit 22b5b8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ abstract class KspAATask @Inject constructor(
cfg.allWarningsAsErrors.value(kspExtension.allWarningsAsErrors)
cfg.excludedProcessors.value(kspExtension.excludedProcessors)

cfg.incremental.value(project.findProperty("ksp.incremental")?.toString()?.toBoolean() ?: true)
cfg.incremental.value(project.providers.gradleProperty("ksp.incremental").orNull?.toBoolean() ?: true)
cfg.incrementalLog.value(
project.findProperty("ksp.incremental.log")?.toString()?.toBoolean() ?: false
project.providers.gradleProperty("ksp.incremental.log").orNull?.toBoolean() ?: false
)

cfg.classpathStructure.from(getClassStructureFiles(project, cfg.libraries))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class KspConfigurations(private val project: Project) {
}

private val allowAllTargetConfiguration =
project.findProperty("ksp.allow.all.target.configuration")?.let {
it.toString().toBoolean()
} ?: true
project.providers.gradleProperty("ksp.allow.all.target.configuration")
.orNull
?.toBoolean()
?: true

// The "ksp" configuration, applied to every compilations.
private val configurationForAll = project.configurations.create(PREFIX).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
options += SubpluginOption("incremental", isIncremental.toString())
options += SubpluginOption(
"incrementalLog",
project.findProperty("ksp.incremental.log")?.toString() ?: "false"
project.providers.gradleProperty("ksp.incremental.log").orNull ?: "false"
)
options += InternalSubpluginOption("projectBaseDir", project.project.projectDir.canonicalPath)
options += SubpluginOption("allWarningsAsErrors", allWarningsAsErrors.toString())
// Turn this on by default to work KT-30172 around. It is off by default in the compiler plugin.
options += SubpluginOption(
"returnOkOnError",
project.findProperty("ksp.return.ok.on.error")?.toString() ?: "true"
project.providers.gradleProperty("ksp.return.ok.on.error").orNull ?: "true"
)
commonSources.ifNotEmpty {
options += FilesSubpluginOption("commonSources", this)
Expand All @@ -148,7 +148,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
)
options += SubpluginOption(
"mapAnnotationArgumentsInJava",
project.findProperty("ksp.map.annotation.arguments.in.java")?.toString() ?: "false"
project.providers.gradleProperty("ksp.map.annotation.arguments.in.java").orNull ?: "false"
)
commandLineArgumentProviders.get().forEach {
it.asArguments().forEach { argument ->
Expand Down Expand Up @@ -176,7 +176,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
val kotlinVersion = ApiVersion.parse(project.getKotlinPluginVersion())!!

// Check version and show warning by default.
val noVersionCheck = project.findProperty("ksp.version.check")?.toString()?.toBoolean() == false
val noVersionCheck = project.providers.gradleProperty("ksp.version.check").orNull?.toBoolean() == false
if (!noVersionCheck) {
if (kspVersion < kotlinVersion) {
project.logger.warn(
Expand Down Expand Up @@ -255,7 +255,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
javaCompile.classpath += project.files(classOutputDir)
}

val processingModel = project.findProperty("ksp.experimental.processing.model")?.toString() ?: "traditional"
val processingModel = project.providers.gradleProperty("ksp.experimental.processing.model").orNull ?: "traditional"

assert(kotlinCompileProvider.name.startsWith("compile"))
val kspTaskName = kotlinCompileProvider.name.replaceFirst("compile", "ksp")
Expand Down Expand Up @@ -402,10 +402,10 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
)
}

val isIncremental = project.findProperty("ksp.incremental")?.toString()?.toBoolean() ?: true
val isIncremental = project.providers.gradleProperty("ksp.incremental")?.orNull?.toBoolean() ?: true
val isIntermoduleIncremental =
(project.findProperty("ksp.incremental.intermodule")?.toString()?.toBoolean() ?: true) && isIncremental
val useKSP2 = project.findProperty("ksp.useKSP2")?.toString()?.toBoolean() ?: false
(project.providers.gradleProperty("ksp.incremental.intermodule").orNull?.toBoolean() ?: true) && isIncremental
val useKSP2 = project.providers.gradleProperty("ksp.useKSP2").orNull?.toBoolean() ?: false

// Create and configure KSP tasks.
val kspTaskProvider = if (useKSP2) {
Expand Down Expand Up @@ -506,8 +506,10 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
configureAsKspTask(kspTask, false)
configureAsAbstractKotlinCompileTool(kspTask)

val useEmbeddable = project.findProperty("kotlin.native.useEmbeddableCompilerJar")
?.toString()?.toBoolean() ?: true
val useEmbeddable = project.providers.gradleProperty("kotlin.native.useEmbeddableCompilerJar")
.orNull
?.toBoolean()
?: true
val classpathCfg = if (useEmbeddable) {
kspClasspathCfg
} else {
Expand Down

0 comments on commit 22b5b8b

Please sign in to comment.