plugins {
    id 'java-library'
    id 'idea'
    id 'maven-publish'
    id 'signing'
}

group = 'fr.flowarg'
version = '1.9.3'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(8)
    }
    withJavadocJar()
    withSourcesJar()
}

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'
    sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    api 'com.google.code.gson:gson:2.13.1'
    api 'fr.flowarg:flowmultitools:1.4.5'
    api 'org.jetbrains:annotations:26.0.2'

    // Only for internal tests
    testImplementation 'fr.flowarg:openlauncherlib:3.2.11'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.withType(Jar).configureEach {
    archiveBaseName.set("flowupdater")
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            pom {
                groupId = project.group
                version = project.version
                artifactId = 'flowupdater'
                name = project.name
                description = 'The free and open source solution to update Minecraft.'
                url = 'https://github.com/FlowArg/FlowUpdater'

                scm {
                    connection = 'scm:git:git://github.com/FlowArg/FlowUpdater.git'
                    developerConnection = 'scm:git:ssh://github.com:FlowArg/FlowUpdater.git'
                    url = 'https://github.com/FlowArg/FlowUpdater/tree/master'
                }

                licenses {
                    license {
                        name = 'GNU General Public License v3.0'
                        url = 'https://www.gnu.org/licenses/gpl-3.0.txt'
                    }
                }

                developers {
                    developer {
                        id = 'flowarg'
                        name = 'Flow Arg'
                        email = 'flow@flowarg.fr'
                    }
                }
            }
        }
    }

    repositories {
        maven {        
            credentials {
                username = System.getenv("NEW_CENTRAL_ID")
                password = System.getenv("NEW_CENTRAL_TOKEN")
            }
            url = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
        }
    }
}

signing {
    def signingKey = System.getenv("GPG_PRIVATE_KEY")
    def signingPassword = System.getenv("GPG_PASSPHRASE")
    useInMemoryPgpKeys(signingKey, signingPassword)
    sign publishing.publications.mavenJava
}

test {
    useJUnitPlatform()
}
