$gradlecleantestpublish:cleanUP-TO-DATE:compileJava:processResourcesUP-TO-DATE:classes:compileTestJava:processTestResourcesUP-TO-DATE:testClasses:test:generatePomFileForSamplePublication:jar:publishSamplePublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar to repository remote at file:/Users/mike/maven-sample-repoTransferring1KfromremoteUploaded1KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-doc.html to repository remote at file:/Users/mike/maven-sample-repoTransferring0KfromremoteUploaded0K:publishBUILDSUCCESSFULTotaltime:18.255secs
pomファイルが発行されたのかどうかよくわかりませんが、
実際に発行されたディレクトリーを見てみます。
build.gradle
1234567891011
$cd/Users/mike/maven-sample-repo/org/mikeneck/sample$lssample-project$cdsample-project/$ ls1.0 maven-metadata.xml maven-metadata.xml.md5 maven-metadata.xml.sha1$ cd 1.0/$lssample-project-1.0-doc.htmlsample-project-1.0.jarsample-project-1.0.pomsample-project-1.0-doc.html.md5sample-project-1.0.jar.md5sample-project-1.0.pom.md5sample-project-1.0-doc.html.sha1sample-project-1.0.jar.sha1sample-project-1.0.pom.sha1
applyplugin:'java'applyplugin:'maven-publish'// project informationgroup='org.mikeneck.sample'version='1.0'// zip sourcestasksourceJar(type:Jar){fromsourceSets.main.allJava}// zip javadocstaskjavadocJar(type:Jar,dependsOn:javadoc){fromjavadoc.destinationDir}// publishing descriptionpublishing{publications{sample(MavenPublication){fromcomponents.javaartifact('document.html'){classifier='doc'extension='html'}artifactsourceJar{classifier='sources'extension='jar'}artifactjavadocJar{classifier='javadoc'extension='jar'}}}repositories{maven{url'file://Users/mike/maven-sample-repo'}}}
$gradlecleantestpublish:clean:compileJava:processResourcesUP-TO-DATE:classes:compileTestJava:processTestResourcesUP-TO-DATE:testClasses:test:generatePomFileForSamplePublication:jar:javadoc:javadocJar:sourceJar:publishSamplePublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar to repository remote at file:/Users/mike/maven-sample-repo/Transferring 1K from remoteUploaded 1KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-doc.htmltorepositoryremoteatfile:/Users/mike/maven-sample-repo/Transferring0KfromremoteUploaded0KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jar to repository remote at file:/Users/mike/maven-sample-repo/Transferring 1K from remoteUploaded 1KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jartorepositoryremoteatfile:/Users/mike/maven-sample-repo/Transferring33KfromremoteUploaded33K:publishBUILDSUCCESSFULTotaltime:25.84secs
applyplugin:'java'applyplugin:'maven-publish'// project informationgroup='org.mikeneck.sample'version='1.0'// zip sourcestasksourceJar(type:Jar){fromsourceSets.main.allJava}// zip javadocstaskjavadocJar(type:Jar,dependsOn:javadoc){fromjavadoc.destinationDir}// publishing descriptionpublishing{publications{// only java archivessample(MavenPublication){fromcomponents.java}// publish documentsdocuments(MavenPublication){artifact('document.html'){classifier='doc'extension='html'}artifactsourceJar{classifier='sources'extension='jar'}artifactjavadocJar{classifier='javadoc'extension='jar'}}}repositories{maven{url'file://Users/mike/maven-sample-repo'}}}
$gradlecleantestpublish:clean:compileJava:processResourcesUP-TO-DATE:classes:compileTestJava:processTestResourcesUP-TO-DATE:testClasses:test:generatePomFileForDocumentsPublication:javadoc:javadocJar:sourceJar:publishDocumentsPublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.pom to repository remote at file:/Users/mike/maven-sample-repo/Transferring 0K from remoteUploaded 0KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-doc.htmltorepositoryremoteatfile:/Users/mike/maven-sample-repo/Transferring0KfromremoteUploaded0KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jar to repository remote at file:/Users/mike/maven-sample-repo/Transferring 1K from remoteUploaded 1KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jartorepositoryremoteatfile:/Users/mike/maven-sample-repo/Transferring33KfromremoteUploaded33K:generatePomFileForSamplePublication:jar:publishSamplePublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar to repository remote at file:/Users/mike/maven-sample-repo/Transferring1KfromremoteUploaded1K:publishBUILDSUCCESSFULTotaltime:12.33secs
$gradlecleanpSPTMR:clean:generatePomFileForSamplePublication:compileJava:processResourcesUP-TO-DATE:classes:jar:publishSamplePublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar to repository remote at file:/Users/mike/maven-sample-repo/Transferring1KfromremoteUploaded1KBUILDSUCCESSFULTotaltime:2.498secs
$gradlecleanpPOPTMR:clean:generatePomFileForPomOnlyPublication:publishPomOnlyPublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.pom to repository remote at file:/Users/mike/maven-sample-repo/Transferring1KfromremoteUploaded1KBUILDSUCCESSFULTotaltime:5.813secs
発行されたpomファイルは次のようになります。
sample-project-1.0.pom
12345678910111213141516171819202122
<?xml version="1.0" encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><modelVersion>4.0.0</modelVersion><groupId>org.mikeneck.sample</groupId><artifactId>sample-project</artifactId><version>1.0</version><packaging>pom</packaging><dependencies><dependency><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.6.3</version></dependency></dependencies><licenses><license><name>The Apache Software License, Version 2.0</name><url>http://www.apache.org/license/LICENSE-2.0.txt</url><distribution>repo</distribution></license></licenses></project>
PGP署名ファイルの発行
少し話題が飛びますが、
maven central repositoryにライブラリーを発行する場合、
各アーカイブファイルとpomファイルに対してPGP(Pretty Good Privacy)署名が必要となります。
$gradlecleanpPpublish:clean:compileJava:processResourcesUP-TO-DATE:classes:jar:javadoc:javadocJar:sourceJar:signArchives:preparePublication:generatePomFileForJarSignaturesPublication:publishJarSignaturesPublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifactsTransferring0KfromremoteUploaded0KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jar.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifactsTransferring0KfromremoteUploaded0KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jar.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifactsTransferring0KfromremoteUploaded0K:generatePomFileForJarsPublication:publishJarsPublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring 1K from remoteUploaded 1KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jartorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring1KfromremoteUploaded1KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jar to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring 33K from remoteUploaded 33K:generatePomFileForPomPublication:publishPomPublicationToMavenRepositoryUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0.pomtorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring1KfromremoteUploaded1K:publishBUILDSUCCESSFULTotaltime:10.894secs
$gpg2--verifysample-project-1.0-javadoc.jar.ascgpg:Signaturemade木6/20 18:05:08 2013 JST using RSA key ID ABC12345gpg: Good signature from "Shinya Mochida (Groovy/JavaScriptDeveloperinJapan)<mike@mikeneck.org>"$ gpg2 --verify sample-project-1.0-sources.jar.ascgpg: Signature made 木 6/20 18:05:08 2013 JST using RSA key ID ABC12345gpg: Good signature from "ShinyaMochida(Groovy/JavaScript Developer in Japan) <mike@mikeneck.org>"$ gpg2 --verify sample-project-1.0.jar.ascgpg: Signature made 木 6/2018:05:082013JSTusingRSAkeyIDABC12345gpg:Goodsignaturefrom"Shinya Mochida (Groovy/JavaScript Developer in Japan) <mike@mikeneck.org>"
// pom fileext{pomFilePath="${project.projectDir}/tmp/pom.xml"pomFile=file(pomFilePath)}// task for signing pomtasksignPom(type:Sign){signpomFile}// getting a signature of pomdefgetPomSignatrure={returnproject.tasks.signPom.signatureFiles.collect{it}[0]}publishing{publications{// publish pompom(MavenPublication){pom.withXml{defnode=asNode()node.chidren().last()+{dependencies{resolveStrategy=Closure.DELEGATE_FIRSTproject.configurations.compile.dependencies.each{dep->dependency{groupIddep.groupartifactIddep.nameversiondep.version}}}}writeTo(project.ext.pomFile)project.tasks.signPom.execute()artifact(getPomSignature()){classifier=nullextension='pom.asc'}}}}}
$gradle--daemoncleanpPpublish:clean:compileJava:processResourcesUP-TO-DATE:classes:jar:javadoc:javadocJar:sourceJar:signArchives:preparePublication:generatePomFileForJarSignaturesPublication:publishJarSignaturesPublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring 0K from remoteUploaded 0KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jar.asctorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring0KfromremoteUploaded0KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jar.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring 0K from remoteUploaded 0K:generatePomFileForJarsPublication:publishJarsPublicationToMavenRepositoryUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jartorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring1KfromremoteUploaded1KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jar to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring 1K from remoteUploaded 1KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jartorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring33KfromremoteUploaded33K:generatePomFileForPomPublication:publishPomPublicationToMavenRepositoryFAILEDFAILURE:Buildfailedwithanexception.*Whatwentwrong:Executionfailedfortask':publishPomPublicationToMavenRepository'.>Failedtopublishpublication'pom'torepository'maven'>Invalidpublication'pom':artifactfiledoesnotexist:'/Users/mike/IdeaProjects/sample-project/tmp/pom.xml.asc'*Try:Runwith--stacktraceoptiontogetthestacktrace.Runwith--infoor--debugoptiontogetmorelogoutput.BUILDFAILEDTotaltime:5.357secs
// declaration of plugins['java','maven-publish','idea','signing'].each{applyplugin:it}// dynamic propertiesext{pomFilePath="${project.projectDir}/tmp/pom.xml"pomFile=file(pomFilePath)}// project informationgroup='org.mikeneck.sample'version='1.0'// repository managementrepositories{mavenCentral()}// dependency managementdependencies{compile'org.jsoup:jsoup:1.6.3'testCompile'junit:junit:4.11'}// zip sourcestasksourceJar(type:Jar){fromsourceSets.main.allJavaclassifier='sources'}// zip javadoctaskjavadocJar(type:Jar,dependsOn:javadoc){fromjavadoc.destinationDirclassifier='javadoc'}// configuration for pom signingconfigurations{pom}// extract artifacts for publishing signaturesartifacts{archivesjararchivessourceJararchivesjavadocJarif(pomFile.exists()){pompomFile}}// jar signintasksignArchives(type:Sign,dependsOn:[jar,sourceJar,javadocJar]){signconfigurations.archives}// getting signature filesdefgetSignatureFiles={defallFiles=tasks.signArchives.signatureFiles.collect{it}defsignedSources=allFiles.find{it.name.contains('-sources')}defsignedJavadoc=allFiles.find{it.name.contains('-javadoc')}defsignedJar=(allFiles-[signedSources,signedJavadoc])[0]return[[archive:signedSources,classifier:'sources',extension:'jar.asc'],[archive:signedJavadoc,classifier:'javadoc',extension:'jar.asc'],[archive:signedJar,classifier:null,extension:'jar.asc']]}// signing pom filetasksignPom(type:Sign){signconfigurations.pom}// prepare publication tasks depends on existence of pom fileif(pomFile.exists()){taskpreparePublication(dependsOn:[signArchives,signPom])}else{taskpreparePublication(dependsOn:signArchives)}// getting pom signaturedefgetPomSignature={returnproject.tasks.signPom.signatureFiles.collect{it}[0]}publishing{publications{// jar publication -- this will be executed lastmainJar(MavenPublication){fromcomponents.java[[jarTask:sourceJar,classifier:'sources',extension:'jar'],[jarTask:javadocJar,classifier:'javadoc',extension:'jar']].each{archive->artifact(archive.jarTask){classifier=archive.classifierextension=archive.extension}}pom.withXml{Nodenode=asNode()node.children().last()+{resolveStrategy=Closure.DELEGATE_FIRSTpackaging'jar'licenses{license{name'The Apache Software License, Version 2.0'url'http://www.apache.org/license/LICENSE-2.0.txt'distribution'repo'}}}if(!project.ext.pomFile.exists()){writeTo(project.ext.pomFile)}}}// publication of jar signaturesjarSignatures(MavenPublication){getSignatureFiles().each{signature->artifact(signature.archive){classifier=signature.classifierextension=signature.extension}}}// publication of pom signatures depends on existence of pom file.if(project.ext.pomFile.exists()){'gpg-pom'(MavenPublication){artifact(getPomSignature()){classifier=nullextension='pom.asc'}}}}repositories{maven{// siwtch repository location by existence of pom fileif(project.ext.pomFile.exists()){// target repositoryurl"file:/${project.projectDir}/artifacts"}else{// temporary repositoryurl"file:/${project.projectDir}/tmp"}}}}
$gradle--daemoncleanpPpublish:clean:compileJava:processResourcesUP-TO-DATE:classes:jar:javadoc:javadocJar:sourceJar:signArchives:preparePublication:generatePomFileForJarSignaturesPublication:publishJarSignaturesPublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/tmp/Transferring 0K from remoteUploaded 0KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jar.asctorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/tmp/Transferring0KfromremoteUploaded0KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jar.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/tmp/Transferring 0K from remoteUploaded 0K:generatePomFileForMainJarPublication:publishMainJarPublicationToMavenRepositoryUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jartorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/tmp/Transferring1KfromremoteUploaded1KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jar to repository remote at file:/Users/mike/IdeaProjects/sample-project/tmp/Transferring 1K from remoteUploaded 1KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jartorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/tmp/Transferring33KfromremoteUploaded33K:publishBUILDSUCCESSFULTotaltime:21.149secs
$gradle--daemoncleanpPpublish:clean:compileJava:processResourcesUP-TO-DATE:classes:jar:javadoc:javadocJar:sourceJar:signArchives:signPomUP-TO-DATE:preparePublication:generatePomFileForGpg-pomPublication:publishGpg-pomPublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.pom.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring 0K from remoteUploaded 0K:generatePomFileForJarSignaturesPublication:publishJarSignaturesPublicationToMavenRepositoryUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar.asctorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring0KfromremoteUploaded0KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jar.asc to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring 0K from remoteUploaded 0KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jar.asctorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring0KfromremoteUploaded0K:generatePomFileForMainJarPublication:publishMainJarPublicationToMavenRepositoryUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0.jar to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring 1K from remoteUploaded 1KUploading: org/mikeneck/sample/sample-project/1.0/sample-project-1.0-sources.jartorepositoryremoteatfile:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring1KfromremoteUploaded1KUploading:org/mikeneck/sample/sample-project/1.0/sample-project-1.0-javadoc.jar to repository remote at file:/Users/mike/IdeaProjects/sample-project/artifacts/Transferring33KfromremoteUploaded33K:publishBUILDSUCCESSFULTotaltime:8.249secs
pom.ascファイルが無事発行されたようです。
それでは、適切なファイルであるかどうか、検証します。
build.gradle
1234
$cdartifacts/org/mikeneck/sample/sample-project/1.0/$gpg2--verifysample-project-1.0.pom.ascgpg:Signaturemade金6/21 04:56:06 2013 JST using RSA key ID ABC12345gpg: Good signature from "Shinya Mochida (Groovy/JavaScriptDeveloperinJapan)<mike@mikeneck.org>"
// declaration of plugins['java','maven-publish','idea','signing'].each{applyplugin:it}// dynamic propertiesext{pomFilePath="${project.projectDir}/tmp/pom.xml"pomFile=file(pomFilePath)}// project informationgroup='org.mikeneck.sample'version='1.0'// repository managementrepositories{mavenCentral()}// dependency managementdependencies{compile'org.jsoup:jsoup:1.6.3'testCompile'junit:junit:4.11'}// zip sourcestasksourceJar(type:Jar){fromsourceSets.main.allJavaclassifier='sources'}// zip javadoctaskjavadocJar(type:Jar,dependsOn:javadoc){fromjavadoc.destinationDirclassifier='javadoc'}// configuration for pom signingconfigurations{pom}// extract artifacts for publishing signaturesartifacts{archivesjararchivessourceJararchivesjavadocJarif(pomFile.exists()){pompomFile}}// jar signintasksignArchives(type:Sign,dependsOn:[jar,sourceJar,javadocJar]){signconfigurations.archives}// getting signature filesdefgetSignatureFiles={defallFiles=tasks.signArchives.signatureFiles.collect{it}defsignedSources=allFiles.find{it.name.contains('-sources')}defsignedJavadoc=allFiles.find{it.name.contains('-javadoc')}defsignedJar=(allFiles-[signedSources,signedJavadoc])[0]return[[archive:signedSources,classifier:'sources',extension:'jar.asc'],[archive:signedJavadoc,classifier:'javadoc',extension:'jar.asc'],[archive:signedJar,classifier:null,extension:'jar.asc']]}// signing pom filetasksignPom(type:Sign){signconfigurations.pom}// prepare publication tasks depends on existence of pom fileif(pomFile.exists()){taskpreparePublication(dependsOn:[signArchives,signPom])}else{taskpreparePublication(dependsOn:signArchives)}// getting pom signaturedefgetPomSignature={returnproject.tasks.signPom.signatureFiles.collect{it}[0]}publishing{publications{// jar publication -- this will be executed lastmainJar(MavenPublication){fromcomponents.java[[jarTask:sourceJar,classifier:'sources',extension:'jar'],[jarTask:javadocJar,classifier:'javadoc',extension:'jar']].each{archive->artifact(archive.jarTask){classifier=archive.classifierextension=archive.extension}}pom.withXml{Nodenode=asNode()node.children().last()+{resolveStrategy=Closure.DELEGATE_FIRSTpackaging'jar'licenses{license{name'The Apache Software License, Version 2.0'url'http://www.apache.org/license/LICENSE-2.0.txt'distribution'repo'}}}if(!project.ext.pomFile.exists()){writeTo(project.ext.pomFile)}}}// publication of jar signaturesjarSignatures(MavenPublication){getSignatureFiles().each{signature->artifact(signature.archive){classifier=signature.classifierextension=signature.extension}}}// publication of pom signatures depends on existence of pom file.if(project.ext.pomFile.exists()){'gpg-pom'(MavenPublication){artifact(getPomSignature()){classifier=nullextension='pom.asc'}}}}repositories{maven{// siwtch repository location by existence of pom fileif(project.ext.pomFile.exists()){// target repositoryurl"file:/${project.projectDir}/artifacts"}else{// temporary repositoryurl"file:/${project.projectDir}/tmp"}}}}