plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
}

ext.isSnapshotVersion = version.endsWith("SNAPSHOT")
ext.isReleaseVersion = !ext.isSnapshotVersion

java {
    sourceCompatibility = 21
    targetCompatibility = 21
}

repositories {
    mavenCentral()
}

dependencies {
    implementation "net.sf.applecommander:ShrinkItArchive:$shkVersion"
    implementation "org.applecommander:acdasm:$acdasmVersion"
    implementation "net.sf.applecommander:bastools-api:$btVersion"
    implementation "org.apache.commons:commons-csv:$commonsCsvVersion"
    implementation "com.google.code.gson:gson:$gsonVersion"

    testImplementation platform("org.junit:junit-bom:$junitVersion")
    testImplementation 'org.junit.jupiter:junit-jupiter'
    testImplementation 'org.junit.jupiter:junit-jupiter-params'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

test {
    useJUnitPlatform()
}

jar {
    archiveBaseName = 'AppleCommander'
    archiveAppendix = 'api'
    manifest {
        attributes 'Implementation-Title': 'AppleCommander',
                   'Implementation-Version': archiveVersion
    }
    from('../../LICENSE')
}

javadoc {
    title = "AppleCommander ${version}"
    source = sourceSets.main.allJava
    options.addStringOption('Xdoclint:none', '-quiet')
}

tasks.register('javadocJar', Jar) {
    archiveClassifier = 'javadoc'
    from javadoc
}

tasks.register('sourcesJar', Jar) {
    archiveClassifier = 'sources'
    from sourceSets.main.allSource
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = "org.applecommander"
            artifactId = "AppleCommander"

            from components.java

            artifact sourcesJar
            artifact javadocJar
            pom {
                name = 'AppleCommander'
                description = 'AppleCommander is a general utility for Apple II disk images.'
                url = 'https://applecommander.github.io/'
                licenses {
                    license {
                        name = 'The GNU General Public License (GPL) Version 2, June 1991'
                        url = 'https://www.gnu.org/licenses/gpl-2.0.html'
                    }
                }
                developers {
                    developer {
                        id = 'robgreene'
                        name = 'Rob Greene'
                        email = 'robgreene@gmail.com'
                    }
                }
                scm {
                    connection = 'scm:git:https://github.com/AppleCommander/AppleCommander.git'
                    developerConnection = 'scm:git:git@github.com:AppleCommander/AppleCommander.git'
                    url = 'https://github.com/AppleCommander/AppleCommander'
                }
            }
            repositories {
                maven {
                    def releasesRepoUrl = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2"
                    def snapshotsRepoUrl = "https://ossrh-staging-api.central.sonatype.com/content/repositories/snapshots/"
                    url = isSnapshotVersion ? snapshotsRepoUrl : releasesRepoUrl
                    credentials {
                        username = findProperty('ossrhUsername')
                        password = findProperty('ossrhPassword')
                    }
                }
            }
        }
    }
}

signing {
    sign publishing.publications.mavenJava
}
