buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id 'org.jetbrains.intellij' version '1.17.3'
    id 'maven-publish'
    id 'signing'
    id 'antlr'
}

wrapper {
    gradleVersion = '8.0.2'
}

group 'org.antlr'
version libraryVersion

apply plugin: 'java'
apply plugin: 'org.jetbrains.intellij'

compileJava {
    sourceCompatibility = '11'
    targetCompatibility = '11'
}

intellij {
    version.set(ideaVersion)

    pluginName.set('antlr4-intellij-adaptor')
    downloadSources.set(true)
    updateSinceUntilBuild.set(false)
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.antlr:antlr4-runtime:$antlr4Version") {
        exclude group: 'com.ibm.icu', module: 'icu4j'
    }
    antlr "org.antlr:antlr4:$antlr4Version"

    testImplementation("junit:junit:4.13.2")
    testImplementation("org.opentest4j:opentest4j:1.3.0")
}

task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    archiveClassifier.set('sources')
    dependsOn(':generateGrammarSource')
}

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

publishing {
    publications {
        maven(MavenPublication) {
            groupId = 'org.antlr'
            artifactId = 'antlr4-intellij-adaptor'
            version = libraryVersion

            from components.java
            artifact sourcesJar
            artifact javadocJar

            pom {
                name = 'ANTLRV4 adaptor for IntelliJ-based IDEs'
                description = 'Support for using ANTLR-generated parsers/lexers in IntelliJ-based IDE plug-ins.'
                url = 'https://github.com/antlr/antlr4-intellij-adaptor'
                licenses {
                    license {
                        name = 'BSD 2-Clause "Simplified" License'
                        url = 'https://github.com/antlr/antlr4-intellij-adaptor/blob/master/LICENSE'
                    }
                }
                developers {
                    developer {
                        id = 'parrt'
                        name = 'Terence Parr'
                        email = 'parrt@antlr.org'
                    }
                }
                scm {
                    connection = 'scm:git:git://github.com/antlr/antlr4-intellij-adaptor.git'
                    developerConnection = 'scm:git:git@github.com:antlr/antlr4-intellij-adaptor.git'
                    url = 'https://github.com/antlr/antlr4-intellij-adaptor'
                }
            }

        }
    }
    repositories {
        maven {
            url "https://oss.sonatype.org/${libraryVersion.contains("-SNAPSHOT") ? 'content/repositories/snapshots' : 'service/local/staging/deploy/maven2'}"
            credentials {
                username = findProperty("ossrhToken") as String
                password = findProperty("ossrhTokenPassword") as String
            }
        }
    }
}

signing {
    afterEvaluate { project ->
        required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
        def signingKey = findProperty("signingKey")
        def signingPassword = findProperty("signingPassword")
        useInMemoryPgpKeys(signingKey, signingPassword)
        sign publishing.publications.maven
    }
}

javadoc {
    if (JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html5', true)
    }
}
