Properties properties = new Properties()
if (project.rootProject.file('gradle.properties').canRead()) {
        properties.load(project.rootProject.file("gradle.properties").newDataInputStream())
}

// Default parameters
ext.nexusUrl = properties.getProperty("nexusUrl", "file:///tmp/sdkRepo")
ext.nexusUsername = properties.getProperty("nexusUsername", "")
ext.nexusPassword = properties.getProperty("nexusPassword", "")

ext.nexusRelease = "${nexusUrl}/service/local/staging/deploy/maven2/"
ext.nexusSnapshot = "${nexusUrl}/content/repositories/snapshots/"

private boolean signingConfigured() {
    return project.hasProperty("signing.keyId") \
      && project.hasProperty("signing.password") \
      && project.hasProperty("signing.secretKeyRingFile")
}

allprojects {
    apply plugin: 'maven'
    if (signingConfigured()) {
        apply plugin: 'signing'
        signing {
            sign configurations.archives
        }
    }

    uploadArchives.repositories.mavenDeployer {
        if (signingConfigured()) {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
        }
        repository(url: nexusRelease) {
            authentication(userName: nexusUsername, password: nexusPassword)
        }

        snapshotRepository(url: nexusSnapshot) {
            authentication(userName: nexusUsername, password: nexusPassword)
        }
    }
}
