Gradleã§Mavenãªãã¸ããªã«ãããã¤ããæã®ã¡ã¢
ãã°ããæ¸ãã¦ããªãã¨å¿ãã¦ãã¾ãã®ã§ã¡ã¢ã
Gradle(Groovy)ãªã®ã§æè»ã«æ¸ãã¡ããã®ã§ããããæ£è§£ã¨ããããã§ã¯ãªãã§ãã
åºæ¬çãªè¨å®
java, mavenãã©ã°ã¤ã³ãè¨å®ããã
apply plugin: 'java' apply plugin: 'maven'
pom.xmlã®groupIdãartifactIdãversionã®å ãã¿ãè¨å®ãããarchiveBaseNameã¯çç¥å¯è½ããã®å ´åãããã¸ã§ã¯ãã®ãã©ã«ãåã使ããã(参考)ãarchivesBaseNameã®ä»£ããã«ãjar.baseName ã§ãOKã
group = 'com.github.wadahiro' archivesBaseName = 'maven-upload-sample' version = '1.0'
uploadArchivesã¿ã¹ã¯ãè¨å®ããã
uploadArchives { repositories { mavenDeployer { repository(url: 'file:/path/to/myrepo') } } }
ããã§ãgradle uploadArchivesãå®è¡ããã¨/path/to/myrepo 以ä¸ã«maven-upload-sample-1.0.jarããããã¤ãããããã«ãªãã
HTTPã§ãªãã¸ããªã«ãããã¤ãã
URLãhttp://ãã«å¤æ´ããã
uploadArchives { repositories { mavenDeployer { repository(url: 'http://mycompany/content/repositories/thirdparty') } } }
èªè¨¼ä»ãã®å ´åã¯ä»¥ä¸ã®ããã«ãããMavenãªãã¸ããªã«Nexusã使ãã¨ããã©ã«ãã§èªè¨¼ä»ããªã®ã§ä»¥ä¸ã®ããã«authenticationã§ã¦ã¼ã¶ã¼IDã»ãã¹ã¯ã¼ããè¨å®ããã
uploadArchives { repositories { mavenDeployer { repository(url: 'http://mycompany/content/repositories/thirdparty') { authentication(userName: "admin", password: "admin123") } } } }
ã½ã¼ã¹ãã¡ã¤ã«ãJavaDocãã¢ãããã¼ããã
ã¾ã以ä¸ã®ã¿ã¹ã¯ã追å ãã*-sources.jarã»*-javadoc.jarãçæãããããã«ããã
task sourcesJar(type: Jar, dependsOn:classes) { classifier = 'sources' from sourceSets.main.allSource } task javadocJar(type: Jar, dependsOn:javadoc) { classifier = 'javadoc' from javadoc.destinationDir }
ããã«ãããããartifactã¨ãã¦èªèãããããã«ãarchiveã¿ã¹ã¯ã§å®ç¾©ããsourcesJarã»javadocJarãæå®ããã
artifactã«ã¤ãã¦è©³ç´°ã¯Chapter 44. Publishing artifactsãåç
§ã®ãã¨ã
artifacts { archives sourcesJar archives javadocJar }
ããã§ãgradle uploadArchivesãå®è¡ããã¨*-sources.jarã»*-javadoc.jarãçæããããªãã¸ããªã«ãããã¤ãããããã«ãªãã
POMã®ããã¸ã§ã¯ãæ å ±ãè¨å®ãã
Mavenã ã¨pom.xmlã«ã©ã¤ã»ã³ã¹ãªã©ããã¸ã§ã¯ãã®æ
å ±ãè¨è¿°ã§ããããã«ãªã£ã¦ãã¾ããgradleããããããã¯è¨å®ã¯å¯è½ã
以ä¸ã®ããã«æ¸ãã¦ããã¨ãgradle uploadArchivesã«ãããããã¤ãgradle installã«ãããã¼ã«ã«Mavenãªãã¸ããª($HOME/.m2/repository)ã¸ã®ã¤ã³ã¹ãã¼ã«æã«çæãããpom.xmlã«åæ ãããããã§ãã
ã¡ãã£ã¨é·ã£ããããã®ã§ãã£ã¨è¯ãæ¸ãæ¹ããªããæ¢ç´¢ä¸...
[install.repositories.mavenInstaller, uploadArchives.repositories.mavenDeployer]*.pom*.whenConfigured { pom -> pom.project { inceptionYear '2012' packaging 'jar' licenses { license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' distribution 'repo' } } } }
POMã®ä¾åé¢ä¿
build.gradleã§è¨å®ããä¾åé¢ä¿ã¯ãèªåçæãããpom.xmlã«ãèªååæ ãããã
ä¾åé¢ä¿ã®å¶å¾¡ã«ã¤ãã¦ã¯å¥éæ¸ãäºå®ã
æçµçãªbuild.gradle
apply plugin: 'java' apply plugin: 'maven' group = 'com.github.wadahiro.gradle-samples' archivesBaseName = 'maven-upload-sample' version = '1.0' uploadArchives { repositories { mavenDeployer { repository(url: 'file:/path/to/myrepo') } } } task sourcesJar(type: Jar, dependsOn:classes) { classifier = 'sources' from sourceSets.main.allSource } task javadocJar(type: Jar, dependsOn:javadoc) { classifier = 'javadoc' from javadoc.destinationDir } artifacts { archives sourcesJar archives javadocJar } [install.repositories.mavenInstaller, uploadArchives.repositories.mavenDeployer]*.pom*.whenConfigured { pom -> pom.project { inceptionYear '2012' packaging 'jar' licenses { license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' distribution 'repo' } } } }