com.codingfeline.buildkonfig.gradle.BuildKonfigExtension.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of buildkonfig-gradle-plugin Show documentation
Show all versions of buildkonfig-gradle-plugin Show documentation
Gradle plugin to generate BuildConfig object for Kotlin MPP
The newest version!
package com.codingfeline.buildkonfig.gradle
import com.codingfeline.buildkonfig.compiler.DEFAULT_KONFIG_OBJECT_NAME
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
open class BuildKonfigExtension(
private val project: Project
) {
private val configFactory = TargetConfigFactory(project.objects, project.logger)
var packageName: String? = null
var objectName: String = DEFAULT_KONFIG_OBJECT_NAME
var exposeObjectWithName: String? = null
val defaultConfigs = mutableMapOf()
val targetConfigs = mutableMapOf>()
@Suppress("unused")
fun defaultConfigs(config: Action) {
defaultConfigs.computeIfAbsent("") { createNewTargetConfig() }
.let {
config.execute(it)
it.flavor = ""
}
}
@Suppress("unused")
fun defaultConfigs(flavor: String, config: Action) {
defaultConfigs.computeIfAbsent(flavor) { createNewTargetConfig() }
.let {
config.execute(it)
it.flavor = flavor
}
}
@Suppress("unused")
fun targetConfigs(config: Action>) {
val container = targetConfigs.computeIfAbsent("") { createTargetConfigContainer() }
config.execute(container)
container.forEach { it.flavor = "" }
}
@Suppress("unused")
fun targetConfigs(flavor: String, config: Action>) {
val container = targetConfigs.computeIfAbsent(flavor) { createTargetConfigContainer() }
config.execute(container)
container.forEach { it.flavor = flavor }
}
private fun createNewTargetConfig(): TargetConfigDsl {
return project.objects.newInstance(
TargetConfigDsl::class.java,
"defaults",
project.logger
)
}
private fun createTargetConfigContainer(): NamedDomainObjectContainer {
return project.container(TargetConfigDsl::class.java, configFactory)
}
}