// tag::all[]
plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
}

group = 'com.example'
version = '1.0'

task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    classifier = 'sources'
}

task javadocJar(type: Jar) {
    from javadoc
    classifier = 'javadoc'
}

// tag::pom-customization[]
publishing {
    publications {
        mavenJava(MavenPublication) {
// end::pom-customization[]
            artifactId = 'my-library'
            from components.java
            artifact sourcesJar
            artifact javadocJar
// tag::pom-customization[]
            pom {
                name = 'My Library'
                description = 'A concise description of my library'
                url = 'http://www.example.com/library'
                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id = 'johnd'
                        name = 'John Doe'
                        email = 'john.doe@example.com'
                    }
                }
                scm {
                    connection = 'scm:git:git://example.com/my-library.git'
                    developerConnection = 'scm:git:ssh://example.com/my-library.git'
                    url = 'http://example.com/my-library/'
                }
            }
        }
    }
// end::pom-customization[]
    repositories {
        maven {
            // change URLs to point to your repos, e.g. http://my.org/repo
            def releasesRepoUrl = "$buildDir/repos/releases"
            def snapshotsRepoUrl = "$buildDir/repos/snapshots"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
        }
    }
// tag::pom-customization[]
}
// end::pom-customization[]

// tag::sign-publication[]
signing {
    sign publishing.publications.mavenJava
}
// end::sign-publication[]


javadoc {
    if(JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html4', true)
    }
}
// end::all[]
