Skip to content

Commit 590846a

Browse files
committed
Make propertyOrEnvOrNull return null if the property is empty
1 parent e88334d commit 590846a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plugins/convention-plugins/src/main/kotlin/PropertyOrEnv.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ internal fun Project.propertyOrEnv(key: String): String {
66
?: error("Didn't find any value for the key \"$key\" in Project properties or environment variables.")
77
}
88

9-
internal fun Project.propertyOrEnvOrNull(key: String): String? {
10-
return findProperty(key) as String? ?: System.getenv(key)
9+
internal fun Project.propertyOrEnvOrNull(
10+
key: String,
11+
nullIfEmpty: Boolean = true
12+
): String? {
13+
return (findProperty(key) as String?)?.takeUnless { nullIfEmpty && it.isEmpty() }
14+
?: System.getenv(key)?.takeUnless { nullIfEmpty && it.isEmpty() }
1115
}

0 commit comments

Comments
 (0)