plugins {
    id 'org.jreleaser' version '1.20.0'
    id 'com.gradle.plugin-publish' version '2.0.0'
}

apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'maven-publish'

group = 'com.avast.gradle'
version = version == 'unspecified' ? 'DEVELOPER-SNAPSHOT' : version
base {
    archivesName = 'gradle-docker-compose-plugin'
}
java {
    sourceCompatibility = JavaVersion.VERSION_1_8
}

repositories {
    mavenCentral()
}

dependencies {
    implementation gradleApi()
    implementation 'org.yaml:snakeyaml:2.5'
    testImplementation gradleTestKit()
    testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
    testImplementation 'org.junit.platform:junit-platform-launcher:1.14.0'
}

test {
    useJUnitPlatform()
    testLogging {
        events 'failed'
        exceptionFormat 'full'
    }
}

java {
    withJavadocJar()
    withSourcesJar()
}

afterEvaluate {
    publishing {
        publications.forEach {
            it.pom {
                name = 'Gradle Docker Compose plugin'
                description = 'Simplifies usage of Docker Compose for integration testing in Gradle environment.'
                url = 'https://github.com/avast/gradle-docker-compose-plugin'
                licenses {
                    license {
                        name = 'The MIT License'
                        url = 'http://www.opensource.org/licenses/mit-license.php'
                    }
                }
                developers {
                    developer {
                        id = 'augi'
                        name = 'Michal Augustýn'
                        email = 'augustyn.michal@gmail.com'
                    }
                }
                scm {
                    connection = 'scm:git:git://github.com/avast/gradle-docker-compose-plugin.git'
                    developerConnection = 'scm:git:ssh://github.com/avast/gradle-docker-compose-plugin.git'
                    url = 'https://github.com/avast/gradle-docker-compose-plugin'
                }
            }
        }
        repositories {
            maven {
                url = layout.buildDirectory.dir('staging-deploy')
            }
        }
    }
}

jreleaser {
    signing {
        active = 'ALWAYS'
        armored = true
        String base64Key = System.getenv('SIGNING_KEY')
        if (base64Key) {
            secretKey = new String(Base64.decoder.decode(base64Key))
        }
        String base64PublicKey = System.getenv('SIGNING_PUBLIC_KEY')
        if (base64PublicKey) {
            publicKey = new String(Base64.decoder.decode(base64PublicKey))
        }
    }
    deploy {
        maven {
            mavenCentral {
                sonatype {
                    active = 'ALWAYS'
                    url = 'https://central.sonatype.com/api/v1/publisher'
                    stagingRepository('build/staging-deploy')
                }
            }
        }
    }
    release {
        github {
            enabled = false
        }
    }
}

gradlePlugin {
    website = 'https://github.com/avast/gradle-docker-compose-plugin'
    vcsUrl = 'https://github.com/avast/gradle-docker-compose-plugin'
    plugins {
        dockerComposePlugin {
            id = 'com.avast.gradle.docker-compose'
            displayName = 'Gradle Docker Compose plugin'
            description = 'Simplifies usage of Docker Compose for integration testing in Gradle environment.'
            implementationClass = 'com.avast.gradle.dockercompose.DockerComposePlugin'
            tags.set(['docker', 'docker-compose'])
        }
    }
}



