apply plugin: 'java-library'
apply plugin: 'java-test-fixtures'
apply plugin: 'jacoco'
apply plugin: 'biz.aQute.bnd.builder'
apply plugin: 'maven-publish'

def defaultEncoding = 'UTF-8'

compileJava {
    options.encoding = defaultEncoding
    options.compilerArgs = ['-Xlint:-options'] // , '-Xlint:unchecked', '-Xlint:deprecation']
}

compileTestJava {
    options.encoding = defaultEncoding
    options.compilerArgs = ['-Xlint:-options'] // , '-Xlint:unchecked', '-Xlint:deprecation']
}

dependencies {
    testImplementation(platform(libs.junit.bom))
    testImplementation 'org.junit.jupiter:junit-jupiter'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    testImplementation libs.mockito.core
    testImplementation libs.mockito.junitjupiter
    testImplementation libs.assertj.core
    testImplementation libs.equalsverifier
    testRuntimeOnly libs.slf4j.simple
}

java {
    withSourcesJar()
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = sourceCompatibility
}

test {
    useJUnitPlatform {
        excludeTags 'elasticsearch'
    }
    systemProperty 'java.awt.headless', 'true'
    systemProperty 'xp.script-engine', project.findProperty("xp.script-engine")?:'Nashorn'
    maxHeapSize = '2G'
    jvmArgs '-XX:TieredStopAtLevel=1'
}


jacocoTestReport {
    dependsOn test
    executionData.from = fileTree(layout.buildDirectory).include("/jacoco/*.exec")
}

def bundleSymbolicName = "${project.group}.${project.name.replace('-', '.')}"
def implementationVersion = project.version

jar {
    bundle {
        bnd( 'Bundle-SymbolicName': bundleSymbolicName,
             '-nouses': 'true',
             '-dsannotations': '*',
             'Implementation-Version': implementationVersion )
    }
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
