/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.6.3/userguide/tutorial_java_projects.html
 */

plugins {
    // Apply the application plugin to add support for building a CLI application
    id 'application'

    // Apply the java plugin to add support for Java
    id 'java'
    
    // Protoc plugin
    id 'com.google.protobuf' version '0.8.19'
    
    id 'eclipse'
}

compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

repositories {
    mavenCentral()
    jcenter()
}

protobuf {
	protoc {
        artifact = 'com.google.protobuf:protoc:3.24.3'
    }
	plugins {
		quickbuf {
			artifact = 'us.hebi.quickbuf:protoc-gen-quickbuf:1.3.1'
		}
	}
	generateProtoTasks {
	    all().each { task ->
			task.builtins {
				remove java
			}
			task.plugins {
				quickbuf {
					//option 'store_unknown_fields=true'
					outputSubDir = ''
				}
			}
	    }
	}
	generatedFilesBaseDir = "$projectDir/src/generated/"
}

dependencies {
    implementation fileTree(dir: 'lib', include: ['*.jar'])

    implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.9'
    implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.4.11'
    implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.11'

    implementation group: 'it.unimi.dsi', name: 'fastutil-core', version: '8.5.12'
    implementation group: 'org.reflections', name: 'reflections', version: '0.10.2'
    
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
    implementation group: 'us.hebi.quickbuf', name: 'quickbuf-runtime', version: '1.3.1'
    
    implementation group: 'io.javalin', name: 'javalin', version: '5.6.2'
    
    implementation group: 'io.netty', name: 'netty-common', version: '4.1.98.Final'
    implementation group: 'io.netty', name: 'netty-handler', version: '4.1.98.Final'
    implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.98.Final'
    implementation group: 'io.netty', name: 'netty-transport-native-kqueue', version: '4.1.98.Final'
    
    implementation group: 'dev.morphia.morphia', name: 'morphia-core', version: '2.3.8'
    implementation group: 'de.bwaldvogel', name: 'mongo-java-server', version: '1.44.0'
    implementation group: 'de.bwaldvogel', name: 'mongo-java-server-h2-backend', version: '1.44.0'
    
    implementation group: 'org.jline', name: 'jline', version: '3.23.0'
    implementation group: 'org.jline', name: 'jline-terminal-jansi', version: '3.23.0'
    
    protobuf files('proto/')

    compileOnly 'org.projectlombok:lombok:1.18.30'
    annotationProcessor 'org.projectlombok:lombok:1.18.30'
}

configurations.all {
    exclude group: 'org.slf4j', module: 'slf4j'
}

clean {
    delete protobuf.generatedFilesBaseDir
}

application {
    // Define the main class for the application
    mainClassName = 'emu.lunarcore.LunarRail'
}

jar {
	exclude '*.proto'

    manifest {
        attributes 'Main-Class': 'emu.lunarcore.LunarRail'
    }

    jar {
        archiveBaseName = 'LunarRail'
        archiveVersion = ''
    }

    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
    
    duplicatesStrategy = DuplicatesStrategy.INCLUDE

    from('src/main/java') {
        include '*.xml'
    }

    getDestinationDirectory().set(file("."))
}

sourceSets {
    main {
        proto {
            srcDir 'src/generated'
        }
        java {
            srcDir 'src/main/java'
        }
    }
}

eclipse {
    classpath {
        file.whenMerged { cp ->
            cp.entries.add( new org.gradle.plugins.ide.eclipse.model.SourceFolder('src/generated/main/', null) )
        }
    }
}

task updateProto {
    group 'Build'
    description 'Cleans generated proto folder and regenerates protos'
    dependsOn 'clean'
    dependsOn 'generateProto'
}

processResources {
    dependsOn 'generateProto'
}