plugins {
	id 'java'
	id 'eclipse'
	id 'application'
	id 'distribution'
	id 'com.gradleup.shadow' version '9.1.0'
	id 'org.openjfx.javafxplugin' version '0.1.0'
	id 'org.beryx.jlink' version '3.1.2'  // Add this for better JavaFX packaging
}

application {
    mainClass = 'com.portalmedia.embarc.gui.Launcher'
}

// GUI Setings
//mainClass = 'com.portalmedia.embarc.gui.Launcher'

// CLI Settings
//mainClassName = 'com.portalmedia.embarc.cli.Main'

version = '1.4.20260622'

repositories {
	mavenCentral()
	mavenLocal()
}

sourceSets {
	main {
		java {
			srcDirs = ['src/main']
		}
		resources {
			srcDirs = ['src/main', 'src/resources']
		}
	}
/*
	test {
		java {
			srcDirs = ['src/tests']
		}
		resources {
			srcDir 'tests/resources'
		}
	}
*/
}

javafx {
    version = '21'
    modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.base', 'javafx.graphics' ]
    configuration = 'implementation'

    run.jvmArgs = ['--add-exports=javafx.graphics/com.sun.javafx.css.parser=ALL-UNNAMED']
}

dependencies {
	implementation 'commons-cli:commons-cli:1.10.0'
	implementation 'commons-collections:commons-collections:3.1'
	implementation 'commons-io:commons-io:2.20.0'
	implementation 'commons-lang:commons-lang:2.6'
	implementation 'org.kordamp.ikonli:ikonli-javafx:12.3.1'
	implementation 'org.kordamp.ikonli:ikonli-fontawesome5-pack:12.3.1'
	implementation 'org.kordamp.ikonli:ikonli-materialdesign-pack:12.3.1'
	implementation 'javax.activation:activation:1.1.1'
	implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'
	implementation 'net.byteseek:byteseek:2.0.3'
	implementation 'net.sf.supercsv:super-csv:2.4.0'
	implementation 'net.sf.trove4j:trove4j:3.0.3'
	implementation 'org.apache.tika:tika-core:3.2.2'
	implementation 'org.controlsfx:controlsfx:11.2.2'
	implementation 'org.dizitart:nitrite:3.1.0'
	implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.5'
	implementation 'org.json:json:20250517'
	implementation files('embARC-maj/target/classes')
	implementation 'uk.gov.nationalarchives:droid-core:6.9.4'
	implementation 'uk.gov.nationalarchives:droid-core-interfaces:6.9.4'

	implementation gradleApi()

	implementation 'junit:junit:4.13.2'

	// Explicit JavaFX dependencies for runtime
	runtimeOnly "org.openjfx:javafx-controls:21:win"
	runtimeOnly "org.openjfx:javafx-controls:21:linux"
	runtimeOnly "org.openjfx:javafx-controls:21:mac"
	runtimeOnly "org.openjfx:javafx-fxml:21:win"
	runtimeOnly "org.openjfx:javafx-fxml:21:linux"
	runtimeOnly "org.openjfx:javafx-fxml:21:mac"
	runtimeOnly "org.openjfx:javafx-base:21:win"
	runtimeOnly "org.openjfx:javafx-base:21:linux"
	runtimeOnly "org.openjfx:javafx-base:21:mac"
	runtimeOnly "org.openjfx:javafx-graphics:21:win"
	runtimeOnly "org.openjfx:javafx-graphics:21:linux"
	runtimeOnly "org.openjfx:javafx-graphics:21:mac"
}

jar {
	manifest {
		attributes(
			'Main-Class': application.mainClass
		)
	}
}

java {
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}

shadowJar {
    zip64 = true

    // Merge service files to avoid JavaFX issues
    mergeServiceFiles()
}

task writeVersionProperties {
    doLast {
        def file = file("${projectDir}/src/main/resources/version.properties")
        file.text = "version=${version}\n"
    }
}

processResources.dependsOn writeVersionProperties

test {
    systemProperties = ['property': 'value']
}
