com.codingfeline.buildkonfig.gradle.TargetConfigDsl.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
package com.codingfeline.buildkonfig.gradle
import com.codingfeline.buildkonfig.compiler.FieldSpec
import com.codingfeline.buildkonfig.compiler.TargetConfig
import org.gradle.api.logging.Logger
import java.io.Serializable
import javax.inject.Inject
open class TargetConfigDsl @Inject constructor(
name: String,
private val logger: Logger
) : TargetConfig(name), Serializable {
companion object {
const val serialVersionUID = 1L
}
@Suppress("unused")
fun buildConfigField(
type: FieldSpec.Type,
name: String,
value: String
) {
val alreadyPresent = fieldSpecs[name]
if (alreadyPresent != null) {
logger.info("TargetConfig: buildConfigField '$name' is being replaced: ${alreadyPresent.value} -> $value")
}
fieldSpecs[name] = FieldSpec(type, name, value)
}
@Suppress("unused")
fun buildConfigNullableField(
type: FieldSpec.Type,
name: String,
value: String?
) {
val alreadyPresent = fieldSpecs[name]
if (alreadyPresent != null) {
logger.info("TargetConfig: buildConfigField '$name' is being replaced: ${alreadyPresent.value} -> $value")
}
fieldSpecs[name] = FieldSpec(type, name, value, nullable = true)
}
fun toTargetConfig(): TargetConfig {
return TargetConfig(name)
.also {
it.flavor = flavor
it.fieldSpecs.putAll(fieldSpecs)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy