diff --git a/README.md b/README.md index 3a6e934..320e986 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,16 @@ buildConfig { > [!NOTE] > `documentation` applies independently for each generated class +## Do not generate classes at Gradle Sync +By default, all `BuildConfigTask`s will be run as part of the Gradle Sync phase, to improve the developer experiece by having always an up-to-date version of the generated BuildConfig classes. + +You can turn this behavior by setting the `com.github.gmazzo.buildconfig.generateAtSync` property to `false` in your `gradle.properties` file or by using the extension DSL: +```kotlin +buildConfig { + generateAtSync = false +} +``` + ## Values greater than 100 characters In some cases, such as embedded public certs, your build config values may exceed 100 characters in length and will become subject to line wrapping by the [Kotlin Poet](https://square.github.io/kotlinpoet/#spaces-wrap-by-default) output. If you need to workaround this behavior, you can explicitly control or prevent line wrapping by replacing spaces with a `ยท` character. diff --git a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/BuildConfigExtension.kt b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/BuildConfigExtension.kt index c2a7933..babd97c 100644 --- a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/BuildConfigExtension.kt +++ b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/BuildConfigExtension.kt @@ -2,9 +2,12 @@ package com.github.gmazzo.buildconfig import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.provider.Property interface BuildConfigExtension : BuildConfigSourceSet { + val generateAtSync: Property + val sourceSets: NamedDomainObjectContainer fun sourceSets(configure: Action>) = configure.execute(sourceSets) diff --git a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/BuildConfigPlugin.kt b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/BuildConfigPlugin.kt index 0686fd3..b8ad507 100644 --- a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/BuildConfigPlugin.kt +++ b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/BuildConfigPlugin.kt @@ -19,6 +19,7 @@ import org.gradle.kotlin.dsl.add import org.gradle.kotlin.dsl.domainObjectContainer import org.gradle.kotlin.dsl.newInstance import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.withType class BuildConfigPlugin : Plugin { @@ -37,6 +38,13 @@ class BuildConfigPlugin : Plugin { sourceSets.configureEach { configureSourceSet(it, defaultSS) } + extension.generateAtSync + .convention(findProperty("com.github.gmazzo.buildconfig.generateAtSync")?.toString()?.toBoolean() ?: true) + .finalizeValueOnRead() + + rootProject.tasks.findByName("prepareKotlinBuildScriptModel") + ?.dependsOn(extension.generateAtSync.map { if (it) tasks.withType() else files() }) + plugins.withId("java") { JavaHandler(project, extension).configure(sourceSets) } diff --git a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/DefaultBuildConfigExtension.kt b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/DefaultBuildConfigExtension.kt index 59128ed..ad6c39b 100644 --- a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/DefaultBuildConfigExtension.kt +++ b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/DefaultBuildConfigExtension.kt @@ -3,7 +3,7 @@ package com.github.gmazzo.buildconfig.internal import com.github.gmazzo.buildconfig.BuildConfigExtension import org.gradle.api.NamedDomainObjectContainer -internal open class DefaultBuildConfigExtension( +internal abstract class DefaultBuildConfigExtension( override val sourceSets: NamedDomainObjectContainer, defaultSourceSet: BuildConfigSourceSetInternal ) : BuildConfigExtension,