// Find property in either System environment or Gradle properties.
// If set in both places, Gradle properties win.
def getPropertyValue(String propertyName) {
    return project.findProperty(propertyName) ?: System.getenv(propertyName) ?: ""
}

// Default values
def rootExt = rootProject.ext
rootExt["signing.keyId"] = '62C0C2F9'
rootExt["sonatypeStagingProfileId"] = 'ossrh'

// Set properties either from a global properties file or environment parameters
rootExt["signBuild"] = getPropertyValue('signBuild')
rootExt["signing.password"] = getPropertyValue('signPassword')
// Apparently Gradle treats properties defined through a gradle.properties file differently
// than those defined through the commandline using `-P`. This is a problem with new
// line characters as found in an ascii-armoured PGP file. To ensure work around this, all newlines
// have been replaced with `#` and thus needs to be reverted here.
rootExt["signing.secretKeyRingFile"] = getPropertyValue('signSecretRingFile').replaceAll('#','\n')
rootExt["ossrhUsername"] = getPropertyValue('ossrhUsername')
rootExt["ossrhPassword"] = getPropertyValue('ossrhPassword')
