diff --git a/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/delegate/EnvironmentVariableDelegate.kt b/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/delegate/EnvironmentVariableDelegate.kt index 9da761e..f84656a 100644 --- a/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/delegate/EnvironmentVariableDelegate.kt +++ b/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/delegate/EnvironmentVariableDelegate.kt @@ -24,8 +24,8 @@ class EnvironmentVariableDelegate( /** * Gets an environment variable in one of two ways: * ```kotlin - * val JAVA_HOME: String by envVar() // Fetches the environment variable named "JAVA_HOME" - * val javaHome: String by envVar("JAVA_HOME") // Fetches the environment variable named "JAVA_HOME" + * val JAVA_HOME by envVar() // Fetches the environment variable named "JAVA_HOME" as a String + * val javaHome by envVar("JAVA_HOME") // Fetches the environment variable named "JAVA_HOME" as a String * ``` * * @param variableName The name of the environment variable to fetch. If diff --git a/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/delegate/GradlePropertyDelegate.kt b/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/delegate/GradlePropertyDelegate.kt index 1ffe515..1941c02 100644 --- a/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/delegate/GradlePropertyDelegate.kt +++ b/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/delegate/GradlePropertyDelegate.kt @@ -4,34 +4,28 @@ import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty import org.gradle.api.Project -class GradlePropertyDelegate( +class GradlePropertyDelegate( private val project: Project, private val variableName: String? = null -) : ReadOnlyProperty { - @Suppress("UNCHECKED_CAST") - override fun getValue(thisRef: Any?, property: KProperty<*>): T { +) : ReadOnlyProperty { + override fun getValue(thisRef: Any?, property: KProperty<*>): String { val nameToUse = variableName ?: property.name - val outcome = project.findProperty(nameToUse) as T - - if (outcome == null) { - throw IllegalStateException("Gradle property variable '$nameToUse' is not set.") - } else { - return outcome - } + val outcome = project.findProperty(nameToUse) as String? + return outcome ?: "" } } /** * Gets a Gradle property in one of two ways: * ```kotlin - * val propertyName: String by propertyValue() // Fetches the value of "propertyName" in gradle.properties - * val property: String by propertyValue("propertyName") // Fetches the value of "propertyName" in gradle.properties + * val propertyName by propertyValue() // Fetches the Gradle Property value of "propertyName" as a String + * val property by propertyValue("propertyName") // Fetches the Gradle Property value of "propertyName" as a String * ``` * * @param propertyName The name of the property to fetch. If `null`, the * name of the Kotlin variable will be used. - * @return The value of the Gradle property. - * @throws IllegalStateException If the Gradle property is not set. + * @return The value of the Gradle property or an empty string if it is + * not set. */ -fun Project.propertyValue(propertyName: String? = null) = - GradlePropertyDelegate(this, propertyName) +fun Project.propertyValue(propertyName: String? = null) = + GradlePropertyDelegate(this, propertyName) diff --git a/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/plugin/CentralRepositoryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/plugin/CentralRepositoryConventionPlugin.kt index e243877..6ae2471 100644 --- a/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/plugin/CentralRepositoryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/com/oliverspryn/gradle/plugin/CentralRepositoryConventionPlugin.kt @@ -3,7 +3,7 @@ package com.oliverspryn.gradle.plugin import com.android.build.api.dsl.LibraryExtension import com.oliverspryn.gradle.BuildConfig import com.oliverspryn.gradle.CentralRepositoryConfig -import com.oliverspryn.gradle.delegate.envVar +import com.oliverspryn.gradle.delegate.propertyValue import com.oliverspryn.gradle.extension.plugins import org.gradle.api.Plugin import org.gradle.api.Project @@ -101,8 +101,8 @@ class CentralRepositoryConventionPlugin : Plugin { } extensions.configure { - val gpgSigningKey: String by envVar("GPG_SIGNING_KEY") - val gpgSigningKeyPassword: String by envVar("GPG_SIGNING_KEY_PASSWORD") + val gpgSigningKey by propertyValue("GPG_SIGNING_KEY") + val gpgSigningKeyPassword by propertyValue("GPG_SIGNING_KEY_PASSWORD") useInMemoryPgpKeys(gpgSigningKey, gpgSigningKeyPassword) sign(extensions.getByType().publications[CentralRepositoryConfig.LIBRARY_NAME])