buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id "java-library"
    id "com.adarshr.test-logger" version "4.0.0"
    id "com.vanniktech.maven.publish" version "0.34.0"
    id "biz.aQute.bnd.builder" version "7.0.0"
}

version = '4.2.1'
group = 'com.github.tschoonj'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

libsDirName = '..'


repositories {
    mavenCentral()
}

dependencies {
	api 'org.apache.commons:commons-numbers-complex:1.2'
	testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
	testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.3'
	testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
}

sourceSets {
	main {
		java {
			srcDir '@srcdir@'
			exclude 'tests/**'
			exclude 'gradle/**'
		}
		resources {
			srcDir '@builddir@'
			include 'xraylib.dat'
		}
	}
	test {
		java {
			srcDir '@srcdir@/tests'
		}
	}
}

jar {
	manifest {
		attributes('Bundle-Vendor': 'Tom Schoonjans',
			'Bundle-SymbolicName': 'com.github.tschoonj.xraylib',
			'Automatic-Module-Name': 'com.github.tschoonj.xraylib',
			'Bundle-Name': project.name,
			'Export-Package': 'com.github.tschoonj.xraylib',
			'-noee': true
		)
	}
}

task checkCompile(type: JavaCompile) {
	source = fileTree('@top_srcdir@/example/') 
	include 'xrlexample7.java'
	classpath = sourceSets.main.runtimeClasspath
	options.sourcepath = files('@top_srcdir@/example')
	destinationDir = file('.')
}


task checkRun(dependsOn: 'checkCompile', type: JavaExec) {
	main = 'xrlexample7'
	classpath = sourceSets.main.runtimeClasspath + files('.')
}

test {
	useJUnitPlatform()
}

// based on https://blog.benoitblanchon.fr/gradle-how-to-make-a-flat-source-jar/
task flatSources(type: Copy) {
	from sourceSets.main.allJava
	into "$buildDir/flatSrc/com/github/tschoonj/xraylib"
}

task sourcesJar(type: Jar, dependsOn: flatSources) {
	from "$buildDir/flatSrc"
	archiveClassifier = 'sources'
}

task javadocJar(type: Jar) {
	from javadoc
	archiveClassifier = 'javadoc'
}

// Maven Central Publishing Configuration using vanniktech plugin
// Updated for Central Publisher Portal (OSSRH EOL as of June 30, 2025)
// This plugin handles all the complexity of Central Portal publishing
// Requires Portal User Token (mavenCentralUsername/mavenCentralPassword)
// and GPG signing configuration
//
// Publishing workflow:
// 1. For snapshots: ./gradlew publishToMavenCentral
// 2. For releases: ./gradlew publishToMavenCentral (then manually publish in Portal)
//    OR: ./gradlew publishAndReleaseToMavenCentral (automatic release)
//
// Login to https://central.sonatype.com/publishing to review deployments
mavenPublishing {
    // Configure for Central Portal publishing
    publishToMavenCentral()
    
    // Enable GPG signing (required for Maven Central)
    signAllPublications()
    
    // Configure POM metadata
    coordinates(group, 'xraylib', version)
    
    pom {
        name = 'xraylib'
        description = 'A library for X-ray matter interaction cross sections for X-ray fluorescence applications'
        inceptionYear = '2009'
        url = 'https://github.com/tschoonj/xraylib'
        
        licenses {
            license {
                name = '3-Clause BSD License'
                url = 'https://opensource.org/licenses/BSD-3-Clause'
                distribution = 'https://opensource.org/licenses/BSD-3-Clause'
            }
        }
        
        developers {
            developer {
                id = 'tschoonj'
                name = 'Tom Schoonjans'
                email = 'Tom.Schoonjans@gmail.com'
                url = 'https://github.com/tschoonj'
            }
        }
        
        scm {
            url = 'https://github.com/tschoonj/xraylib'
            connection = 'scm:git:git://github.com/tschoonj/xraylib.git'
            developerConnection = 'scm:git:ssh://git@github.com/tschoonj/xraylib.git'
        }
    }
}