plugins {
    id 'java'
    id 'application'
}

// ------------------------------------
// Hal common configuration
// ------------------------------------

allprojects {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }
}

subprojects {
    apply plugin: 'java-library'

    dependencies {
        implementation 'se.koc:zutil:1.0.0-SNAPSHOT'

        testImplementation 'junit:junit:4.12'
        testImplementation 'org.hamcrest:hamcrest-core:2.2'
    }

    sourceSets {
        main {
            java {
                srcDirs 'src'
            }
            //resources {
            //    srcDir 'resource'
            //}
        }
        test {
            java {
                srcDirs 'test'
            }
        }
    }
}

// ------------------------------------
// Hal core configuration
// ------------------------------------

dependencies {
    project.subprojects.each { subProject ->
        runtime subProject
    }
}

distributions {
    main {
        contents {
            from 'hal.conf.example'
            from 'hal-default.db'
            from 'logging.properties'

            from "${buildDir}/resources"
        }
    }
}

task copyRecources(type: Copy) {
    doFirst{
        System.out.println("Copying resource files...")
    }

    project.subprojects.each { subProject ->
        from "${subProject.projectDir}/resource"
    }

    into("${buildDir}/resources")
}

processResources.finalizedBy(copyRecources)

application {
    mainClass = 'se.hal.HalServer'
}