plugins {
    id 'com.jessebrault.ssg' version '0.4.0'
    id 'distribution'
}

group = 'com.jessebrault'
version = '0.1.0'

repositories {
    mavenCentral()
    mavenLocal()
}

configurations {
    server
}

sourceSets {
    server
}

dependencies {
    implementation 'org.apache.groovy:groovy:4.0.21'

    serverImplementation 'org.eclipse.jetty:jetty-server:12.0.9'
    serverImplementation 'info.picocli:picocli:4.7.6'
    serverRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1'
}

tasks.register('serverJar', Jar) {
    group = 'build'
    archiveBaseName = 'jb-ssg-site-server'
    from sourceSets.server.java.classesDirectory
    from sourceSets.server.resources.files
}

tasks.register('serverStartScripts', CreateStartScripts) {
    applicationName = 'JbServer'
    mainClass = 'com.jessebrault.site.JbServer'
    classpath = files(configurations.serverRuntimeClasspath.files.collect {
        java.nio.file.Path.of('lib', it.name).toFile()
    })
    classpath += files(tasks.named('serverJar', Jar).get().outputs.files.collect { it.name })
    outputDir = file('build/tmp/serverStartScripts')
}

distributions {
    server {
        contents {
            from(serverStartScripts) {
                into 'bin'
            }
            from(serverJar) {
                into 'lib'
            }
            from(configurations.serverRuntimeClasspath.files) {
                into 'lib'
            }
        }
    }
}
