Skip to content

Commit

Permalink
Generate build config class at Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Jan 2, 2024
1 parent 556c0e1 commit 18e328f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean>

val sourceSets: NamedDomainObjectContainer<out BuildConfigSourceSet>

fun sourceSets(configure: Action<NamedDomainObjectContainer<out BuildConfigSourceSet>>) = configure.execute(sourceSets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {

Expand All @@ -37,6 +38,13 @@ class BuildConfigPlugin : Plugin<Project> {

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<BuildConfigTask>() else files() })

plugins.withId("java") {
JavaHandler(project, extension).configure(sourceSets)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuildConfigSourceSetInternal>,
defaultSourceSet: BuildConfigSourceSetInternal
) : BuildConfigExtension,
Expand Down

0 comments on commit 18e328f

Please sign in to comment.