Maven CentralにGradleでリリースしてみた

と言ってもやったことは、基本参考ページを見ながら順番に進めていっただけ。意外と公式ドキュメントに情報が揃っていることが分かったが、そもそもそこにたどり着くために参考ページが役に立った。

リリースした雑ライブラリは以下。

github.com

最終的な build.gradleは以下。

https://github.com/eiryu/templa/blob/8ce567bb422df0f3ed0d4c6dadaf8fc4c4169c2d/build.gradle

apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'signing'


description = 'A New HTML Template Engine'
group = 'com.eiryu'
version = '0.1.0'
archivesBaseName = 'templa'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

[compileJava, compileTestJava, compileGroovy, compileTestGroovy].each {
    it.options.encoding = 'UTF-8'
}

repositories {
    mavenLocal()
    jcenter()
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.3'

    testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
    testCompile 'junit:junit:4.12'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.5'
}

task javadocJar(type: Jar, dependsOn: groovydoc) {
    classifier = 'javadoc'
    from "${buildDir}/javadoc"
}

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

artifacts {
    archives jar
    archives javadocJar
    archives sourcesJar
}

signing {
    sign configurations.archives
}

uploadArchives {
    repositories {
        mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: ossrhUsername, password: ossrhPassword)
            }

            snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                authentication(userName: ossrhUsername, password: ossrhPassword)
            }

            pom.project {
                name 'Templa'
                packaging 'jar'
                description project.description
                url 'https://github.com/eiryu/templa'

                scm {
                    connection 'scm:git:https://github.com/eiryu/templa.git'
                    developerConnection 'scm:git:https://github.com/eiryu/templa.git'
                    url 'https://github.com/eiryu/templa.git'
                }

                licenses {
                    license {
                        name 'The MIT License (MIT)'
                        url 'http://opensource.org/licenses/MIT'
                    }
                }

                developers {
                    developer {
                        id 'eiryu'
                        name 'Hidetaka Koda'
                        email 'eiryu.co@gmail.com'
                    }
                }
            }
        }
    }
}

つまずいた・気になったところ

  • sonatypeにuploadする際に、Could not find metadataと出たが問題なく上がっていた
$ ./gradlew --daemon uploadArchives
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:groovydoc UP-TO-DATE
:javadocJar UP-TO-DATE
:sourcesJar UP-TO-DATE
:signArchives UP-TO-DATE
:uploadArchives
Could not find metadata com.eiryu:templa:0.1.0-SNAPSHOT/maven-metadata.xml in remote (https://oss.sonatype.org/content/repositories/snapshots/)
Could not find metadata com.eiryu:templa/maven-metadata.xml in remote (https://oss.sonatype.org/content/repositories/snapshots/)

BUILD SUCCESSFUL

Total time: 25.408 secs
  • SNAPSHOTはMaven Centralに同期されないらしい。参考

  • リリースがちょっと分かりにくかったが、ちゃんと英語を読めば手順が書いてあった。Staging RepositoryをClose、Releaseの順番で操作してリリースする

  • 最初GPG鍵を作ってはいたが公開鍵サーバーに送っていなかったせいで、Staging RepositoryのClose処理で鍵のVerifyエラーが発生してしまった

参考