// Sets up publishing of release artifacts.
// Note: Keep this script in sync across all airbnb open source projects.
apply plugin: 'com.vanniktech.maven.publish'


// https://vanniktech.github.io/gradle-maven-publish-plugin/other/
publishing {
    repositories {
        maven {
            // The "name" value creates a task like `publishAllPublicationsTo[Name]Repository
            // In this case, publishAllPublicationsToAirbnbArtifactoryRepository
            name = 'airbnbArtifactory'
            url = version.toString().endsWith("SNAPSHOT") ? findProperty("ARTIFACTORY_SNAPSHOT_URL") : findProperty("ARTIFACTORY_RELEASE_URL")
            credentials {
                username = findProperty("ARTIFACTORY_USERNAME")
                password = findProperty("ARTIFACTORY_PASSWORD")
            }
        }
    }
}

mavenPublishing {
    if (findProperty("enforceSnapshotVersion").toString().toBoolean() && !findProperty("VERSION_NAME").toString().endsWith("-SNAPSHOT")) {
        throw new org.gradle.api.tasks.TaskInstantiationException(
                "Cannot publish non snapshot version(${findProperty("VERSION_NAME")}) if 'enforceSnapshotVersion' property is set!"
        )
    }
    if (findProperty("doNotSignRelease").toString().toBoolean()) {
        println("Skipping release signing")
    } else {
        println("Signing release with gpg")
        signAllPublications()
    }
}