Maven Artifacts如何部署到倉(cāng)庫(kù)
順利
說明:該文檔只對(duì)有一定的Maven使用基礎(chǔ)的人有效,我也不會(huì)說的太具體,主要是一些配置和注意點(diǎn)。還有本文所用環(huán)境是Maven3,并不保證Maven2都能夠成功運(yùn)行。不好意思,沒有太多時(shí)間來測(cè)試環(huán)境。
一、本地倉(cāng)庫(kù)
使用 Nexus,如何搭建 Nexus 本文也就不說了。
pom.xml
<distributionManagement>
<repository>
<id>proj-releases</id>
<name>Proj Release Repository</name>
<url>http://localhost:8080/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>proj-snapshots</id>
<name>Proj Snapshots Repository</name>
<url>http://localhost:8080/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
settings.xml
<servers>
<server>
<id>proj-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>proj-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
二、Google Code 遠(yuǎn)程倉(cāng)庫(kù)
2.1 第一種方案 使用wagon-webdav來遠(yuǎn)程上傳repo
參考:http://marshal.easymorse.com/archives/2644
pom.xml
<distributionManagement>
<repository>
<id>usc-google-code-repo</id>
<name>Google Code Repo for USC (releases)</name>
<url>dav:https://usc.googlecode.com/svn/maven-repo/releases</url>
<uniqueVersion>false</uniqueVersion>
</repository>
<snapshotRepository>
<id>usc-google-code-snapshot</id>
<name>Google Code Repo USC (snapshots)</name>
<url>dav:https://usc.googlecode.com/svn/maven-repo/snapshots</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
</extensions>
</build>
settings.xml
<servers>
<server>
<id>usc-google-code-repo</id>
<username>your google email</username>
<password>your google code project password</password>
</server>
<server>
<id>usc-google-code-snapshot</id>
<username>your google email</username>
<password>your google code project password</password>
</server>
</servers>
注意點(diǎn)
1.repo url 是 dav: ...
2.其他project or module 依賴使用的時(shí)候, 請(qǐng)加上 repositories 和 group id..
e.g.
<repositories>
<repository>
<id>usc-google-code-repo</id>
<name>Google Code Repo for USC (releases)</name>
<url>https://usc.googlecode.com/svn/maven-repo/releases</url>
</repository>
</repositories>
2.2 第二種方案 使用wagon-svn來遠(yuǎn)程上傳repo
參考:http://www.dev-articles.com/article/Google-Code-personal-maven-repository-30001
pom.xml
<distributionManagement>
<repository>
<id>usc-google-code-repo</id>
<name>Google Code Repo for USC (releases)</name>
<url>svn:https://usc.googlecode.com/svn/maven-repo/releases</url>
<uniqueVersion>false</uniqueVersion>
</repository>
<snapshotRepository>
<id>usc-google-code-snapshot</id>
<name>Google Code Repo USC (snapshots)</name>
<url>svn:https://usc.googlecode.com/svn/maven-repo/snapshots</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.jvnet.wagon-svn</groupId>
<artifactId>wagon-svn</artifactId>
<version>1.9</version>
</extension>
</extensions>
</build>
settings.xml
<servers>
<server>
<id>usc-google-code-repo</id>
<username>your google email</username>
<password>your google code project password</password>
</server>
<server>
<id>usc-google-code-snapshot</id>
<username>your google email</username>
<password>your google code project password</password>
</server>
</servers>
注意點(diǎn)
1.repo url 是 svn: ...
2.其他project or module 依賴使用的時(shí)候, 請(qǐng)加上 repositories 和 group id..
e.g.
<repositories>
<repository>
<id>usc-google-code-repo</id>
<name>Google Code Repo for USC (releases)</name>
<url>https://usc.googlecode.com/svn/maven-repo/releases</url>
</repository>
</repositories>
3.好像有個(gè)權(quán)限認(rèn)證的問題,會(huì)有選擇,選擇最后一項(xiàng) p: (p)ermanently(永久)應(yīng)該是ok的.
信息差不多如下:
Uploading: svn:https://usc.googlecode.com/svn/maven-repo/releases/org/usc/file/filename-batch-converter/app-parent/3.0.5/app-parent-3.0.5.pom
Error validating server certificate for 'https://usc.googlecode.com:443':
- The certificate is not issued by a trusted authority. Use the
fingerprint to validate the certificate manually!
- The certificate hostname does not match.
Certificate information:
- Subject: CN=*.googlecode.com, O=Google Inc, L=Mountain View, ST=California, C=US
- Valid: from Fri Aug 12 11:49:18 CST 2011 until Sun Aug 12 11:59:18 CST 2012
- Issuer: CN=Google Internet Authority, O=Google Inc, C=US
- Fingerprint: 28:92:6b:9b:40:10:cc:0e:4c:16:a4:78:7f:bb:1a:8d:d4:d1:d3:27
(R)eject, accept (t)emporarily or accept (p)ermanently?
個(gè)人感覺使用wagon-svn沒有使用wagon-webdav deploy 快,可能是使用協(xié)議的問題。
2.3 第三種方案(這才是遠(yuǎn)程)
上面的兩種方法,都必須要配置 repository,如果是普通用戶,并不會(huì)關(guān)注到這些倉(cāng)庫(kù)配置,當(dāng)他們不配置這些倉(cāng)庫(kù)URL的,又想使用你的Jar,可否?能否直接使用 group id + artifactId + version 就能依賴到了,答案是肯定的。使用 OSS Sonatype一個(gè)代理 Repository,過一段時(shí)間會(huì)更新到Maven Central Repo。
參考
https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide
http://maven.apache.org/plugins/maven-gpg-plugin/usage.html
https://issues.sonatype.org/browse/OSSRH-2171
這種方法,需要等待許許時(shí)間,需要Juven Xu進(jìn)行”bug fix”,開通后,需要和Juven進(jìn)行交流,完畢后,就可以部署你的Artifacts到OSS Repo里面,最后一步,會(huì)進(jìn)行激活同步到中央倉(cāng)庫(kù)(http://repo1.maven.org/)中。
我成功部署的Artifacts 路徑如下
OSS Repo
https://oss.sonatype.org/content/groups/staging/com/googlecode/usc/
Maven Central Repo
http://repo1.maven.org/maven2/com/googlecode/usc/

好了,現(xiàn)在你就可以通過下面的配置直接依賴我的Jar包了,不需要配置額外的repo。
<dependency>
<groupId>com.googlecode.usc</groupId>
<artifactId>filename-batch-converter-main</artifactId>
<version>3.0.8</version>
</dependency>
注意點(diǎn):
1.命名盡量以 com.googlecode. 開頭,比如 com.googlecode.usc
參考 https://docs.sonatype.org/display/Repository/Choosing+your+Coordinates
2. Maven Release Plugin 使用最新版可能有些問題,建議使用2.0-beta-8 ,我用這個(gè)已經(jīng)成功release到遠(yuǎn)程
3.還是Maven Release Plugin的問題,SVN 的路徑盡量保持規(guī)范,即 trunk,tags, brances
4.這個(gè)過程可能有點(diǎn)點(diǎn)漫長(zhǎng),希望大家耐心等待,還有說是兩個(gè)小時(shí)同步一次,但是據(jù)我使用,感覺沒有,可能是一個(gè)假象吧,不過能夠使用,結(jié)局還是很歡喜的。
使用這種方法請(qǐng)感謝Juven Xu,是他的幫助使我們更加快捷高效地使用Maven,讓共享成為一種樂趣。
上面的所有配置,你都可以在我的google code中找到,你可以通過下面的URL來SVN check out
http://usc.googlecode.com/svn/trunk/filename-batch-converter/
你也可以直接瀏覽
http://usc.googlecode.com/svn/trunk/filename-batch-converter/filename-batch-converter-parent/pom.xml
主要是這個(gè)pom配置文件。還有這個(gè)project中還有一些其它好玩的東西(比如打包,如何生成exe文件等。),應(yīng)該會(huì)在后面進(jìn)行分享。
如果有什么建議或意見可以通過微博 http://weibo.com/lishunli(左上側(cè)直接加關(guān)注)或QQ:506817493(QQ白天經(jīng)常不在線,建議微博交流,謝謝),大家一起交流學(xué)習(xí)。
最后弱弱地說一下,如果可以的話,轉(zhuǎn)載請(qǐng)?zhí)峁┰?/font>URL。謝謝。
2011年9月7日
李順利
博客中的一些下載已經(jīng)放到了百度云了,請(qǐng)根據(jù)需要下載。【點(diǎn)我去百度云下載】
最后弱弱地說一下,如果可以的話,轉(zhuǎn)載請(qǐng)?zhí)峁┏鎏?
),謝謝。
posted on 2011-09-07 00:46
李順利 閱讀(5708)
評(píng)論(0) 編輯 收藏 所屬分類:
Maven