plugins {
    id 'java-module' // buildSrc/src/main/groovy/java-module.gradle
    id 'maven-publish'
}

java {
    withJavadocJar()
    withSourcesJar()
}

javadoc {
    options.encoding = 'UTF-8'
    options.addStringOption('Xdoclint:none', '-quiet')
}

publishing {
    publications {
        library(MavenPublication) {
            from components.java
            versionMapping {
                usage('java-api') {
                    fromResolutionOf('runtimeClasspath')
                }
                usage('java-runtime') {
                    fromResolutionResult()
                }
            }
        }
    }

    repositories {
        mavenLocal()
        if (project.hasProperty('publishUrl')) {
            maven {
                name 'customRepo'
                url project.property('publishUrl')
                credentials {
                    username = project.hasProperty('publishUsername') ? project.property('publishUsername') : ''
                    password = project.hasProperty('publishPassword') ? project.property('publishPassword') : ''
                }
            }
        }
    }
}