plugins {
    id 'application'
}

def MAIN_CLASS = 'io.github.headlesshq.headlessmc.web.cheerpj.Main'
application {
    mainClass = MAIN_CLASS
}

dependencies {
    jarLibsApi project(':headlessmc-launcher-wrapper')
}

processResources {
    into('headlessmc') {
        from project(':headlessmc-launcher')['shadowJar']
        from project(':headlessmc-web-plugin')['shadowJar']
        rename 'headlessmc-launcher(.*).jar', 'headlessmc-launcher.jar'
        rename 'headlessmc-web-plugin(.*).jar', 'headlessmc-web-plugin.jar'
    }
}

jar {
    manifest {
        attributes('Main-Class': MAIN_CLASS)
    }
}

// see launcher build.gradle
tasks.register('shadowBugWorkaround', Jar) {
    dependsOn jar
    dependsOn project(':headlessmc-web-plugin')['shadowJar']

    destinationDirectory.set(layout.buildDirectory.dir('shadow-bug-workaround'))

    into ('headlessmc') {
        from project(':headlessmc-web-plugin')['shadowJar']
        rename 'headlessmc-web-plugin(.*).jar', 'headlessmc-web-plugin.jar'
    }
}

shadowJar {
    dependsOn shadowBugWorkaround
    from shadowBugWorkaround
    from layout.buildDirectory.dir('shadow-bug-workaround')
}
