plugins {
    id 'com.android.library'
    id 'maven-publish'
    id 'signing'
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

if (gradle.ext.gpr != null) {
    repositories {
        maven {
            name = "github"
            url = "https://maven.pkg.github.com/enioka-Haute-Couture/enioka_scan_drivers"
            credentials {
                username = project.findProperty("gpr.user") ?: System.getenv("GH_DRIVER_REPOSITORY_USERNAME")
                password = project.findProperty("gpr.key") ?: System.getenv("GH_DRIVER_REPOSITORY_TOKEN")
            }
        }
    }
}

ext {
    mavenArtifactId = null
}

android {
    namespace 'com.enioka.scanner'
    publishing {
        singleVariant('release') {
            withSourcesJar()
            withJavadocJar()
        }
    }

    // TODO: reactivate this
    lintOptions {
        disable 'MissingPermission'
    }
}

signing {
    useInMemoryPgpKeys(
            System.getenv("SIGN_KEYID"),
            System.getenv("SIGN_KEY"),
            System.getenv("SIGN_PASSWORD")
    )
    sign publishing.publications
}


afterEvaluate {
    if (project.ext.mavenArtifactId != null) {
        publishing {
            repositories {
                maven {
                    name = "OSSRH"
                    url = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
                    credentials {
                        username = System.getenv("OSSRH_LOGIN")
                        password = System.getenv("OSSRH_PASSWORD")
                    }
                }
            }

            publications {
                release(MavenPublication) {
                    groupId 'com.enioka.scanner'
                    artifactId project.ext.mavenArtifactId
                    version System.getenv("LIB_VERSION")

                    from components.release

                    pom {
                        name = 'Enioka Scan - ' + project.name
                        description = project.description
                        url = 'https://github.com/enioka/enioka_scan'
                        licenses {
                            license {
                                name = 'The Apache License, Version 2.0'
                                url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                            }
                        }
                        scm {
                            connection = 'scm:git:github.com/enioka/enioka_scan.git'
                            developerConnection = 'scm:git:ssh://github.com/enioka/enioka_scan.git'
                            url = 'https://github.com/enioka/enioka_scan/tree/master'
                        }
                        developers {
                            developer {
                                id = 'mag'
                                name = 'Marc-Antoine Gouillart'
                                email = 'mag@enioka.com'
                            }
                        }
                    }
                }
            }
        }
    }
}
