import com.vanniktech.maven.publish.SonatypeHost

plugins {
    id 'java-library'
    alias(libs.plugins.vanniktech.maven.publish)
}


def project_name = "USB Device Enumerator"
def project_description = "A library to collect USB device data from /sys/bus/usb/"
def github_owner_and_repo = "alt236/USB-Device-Info---Android"
def group_id = 'dev.alt236'
def artifact_id = 'usbdeviceenumerator'
def artifact_version = '3.0.0'

group group_id
version artifact_version

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

test {
    jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
}

dependencies {
    compileOnly libs.jsr305
    testImplementation libs.mockito
    testImplementation libs.junit4
}

mavenPublishing { // This is for the 'vanniktech-maven-publish' plugin
    var automaticRelease = false
    publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease)
    signAllPublications()

    coordinates(group_id, artifact_id, artifact_version)
    pom {
        name = project_name
        description = project_description
        url = "https://github.com/$github_owner_and_repo"
        licenses {
            license {
                name = 'The Apache License, Version 2.0'
                url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                distribution = "http://www.apache.org/licenses/LICENSE-2.0.txt"
            }
        }
        developers {
            developer {
                id = 'alt236'
                name = 'Alexandros Schillings'
                url = "https://github.com/alt236/"
            }
        }
        scm {
            url = "https://github.com/$github_owner_and_repo"
        }
    }
}

// Fix for dependency order issue: https://github.com/vanniktech/gradle-maven-publish-plugin/issues/814
afterEvaluate {
    var sigDependentTasks = [
            "publishMavenPublicationToMavenCentralRepository",
    ]

    for (taskName in sigDependentTasks) {
        tasks.named(taskName) {
            println("Found: " + it.name)
            dependsOn("signMavenPublication")
        }
    }
}

