task copyRuntimeLibs(type: Copy) {
    into project.jar.destinationDirectory
    from configurations.runtimeClasspath
    exclude "${project.name}.jar"
    duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
}
copyRuntimeLibs.dependsOn(addDependenciesModuleInfo)
jar.dependsOn(copyRuntimeLibs)

def dev = tasks.register('createDevOutput', Copy) {
    mustRunAfter copyRuntimeLibs, jar

    if (project.allExtensions.contains(project)) {
        var source = "${project.jar.destinationDirectory.get()}"
        from source
        into "${project.rootDir}/app/build/ext_dev/$project.name"
    }
}
jar.finalizedBy(dev)

tasks.register('createExtOutput', Copy) {
    mustRunAfter copyRuntimeLibs, jar

    if (!file("${project.jar.destinationDirectory.get()}_prod").exists()) {
        copy {
            from "${project.jar.destinationDirectory.get()}"
            into "${project.jar.destinationDirectory.get()}_prod"
        }
    }

    def shouldObfuscate = rootProject.obfuscate && rootProject.privateExtensions.contains(project.name)
    var source = shouldObfuscate ? "${project.jar.destinationDirectory.get()}_prod" : "${project.jar.destinationDirectory.get()}"

    from source
    into "${project.jar.destinationDirectory.get()}_ext"
}

apply from: "$rootDir/gradle/gradle_scripts/java.gradle"
apply from: "$rootDir/gradle/gradle_scripts/javafx.gradle"
apply from: "$rootDir/gradle/gradle_scripts/lombok.gradle"
apply from: "$rootDir/gradle/gradle_scripts/extension_test.gradle"

dependencies {
    compileOnly group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "2.15.2"
    compileOnly project(':core')
    compileOnly project(':beacon')
    compileOnly project(':app')
    compileOnly 'net.synedra:validatorfx:0.3.1'
    compileOnly ('io.github.mkpaz:atlantafx-base:2.0.1') {
        exclude group: 'org.openjfx', module: 'javafx-base'
        exclude group: 'org.openjfx', module: 'javafx-controls'
    }

    if (project != project(':base')) {
        compileOnly project(':base')
        testImplementation project(':base')
    }

    testImplementation project(':app')
}

