apply plugin: 'org.openjfx.javafxplugin'
apply plugin: 'com.github.johnrengelman.shadow'

String mainClassName = "pro.gravit.launcher.start.ClientLauncherWrapper"
String mainAgentName = "pro.gravit.launcher.runtime.LauncherAgent"

repositories {
    maven {
        url "https://repo.spring.io/plugins-release/"
    }
}
javafx {
    version = "12"
    modules = ['javafx.controls', 'javafx.fxml']
}
sourceCompatibility = '17'
targetCompatibility = '17'

configurations {
    bundle
    pack
    api.extendsFrom bundle, pack
}

jar {
    archiveClassifier.set('clean')
    manifest.attributes("Main-Class": mainClassName,
            "Premain-Class": mainAgentName,
            "Multi-Release": "true",
            "Automatic-Module-Name": "GravitLauncher")
}

tasks.register('sourcesJar', Jar) {
    from sourceSets.main.allJava
    archiveClassifier.set('sources')
}

tasks.register('javadocJar', Jar) {
    from javadoc
    archiveClassifier.set('javadoc')
}

shadowJar {
    duplicatesStrategy = 'EXCLUDE'
    archiveClassifier.set(null)
    relocate 'io.netty', 'pro.gravit.repackage.io.netty'
    configurations = [project.configurations.pack]
    exclude 'module-info.class'
}

dependencies {
    pack project(':LauncherAPI')
    pack project(':LauncherClient')
    pack project(':LauncherStart')
    bundle(group: 'com.github.oshi', name: 'oshi-core', version: rootProject['verOshiCore']) {
        exclude group: 'org.slf4j'
    }
}

tasks.register('genRuntimeJS', Zip) {
    duplicatesStrategy = 'EXCLUDE'
    archiveFileName = "runtime.zip"
    destinationDirectory = file("${buildDir}/tmp")
    from "runtime/"
}

tasks.register('dumpLibs', Copy) {
    duplicatesStrategy = 'EXCLUDE'
    into "$buildDir/libs/libraries"
    from configurations.bundle
}


assemble.dependsOn tasks.genRuntimeJS, tasks.dumpLibs, tasks.shadowJar

publishing {
    publications {
        launcherclientapi(MavenPublication) {
            artifactId = 'launcher-client-api'
            artifact(jar) {
                classifier ""
            }
            artifact sourcesJar
            artifact javadocJar
            pom {
                name = 'GravitLauncher Client API'
                description = 'GravitLauncher Client Module API'
                url = 'https://gravitlauncher.com'
                licenses {
                    license {
                        name = 'GNU General Public License, Version 3.0'
                        url = 'https://www.gnu.org/licenses/gpl-3.0.html'
                    }
                }
                developers {
                    developer {
                        id = 'gravita'
                        name = 'Gravita'
                        email = 'gravita@gravit.pro'
                    }
                    developer {
                        id = 'zaxar163'
                        name = 'Zaxar163'
                        email = 'zahar.vcherachny@yandex.ru'
                    }
                }
                scm {
                    connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git'
                    developerConnection = 'scm:git:ssh://git@github.com:GravitLauncher/Launcher.git'
                    url = 'https://gravitlauncher.com/'
                }
            }
        }
    }
}


signing {
    sign publishing.publications.launcherclientapi
}