李順利
          隨筆-50  評論-170  文章-0  trackbacks-0

          Maven Artifacts如何部署到倉庫

          順利

           

          說明:該文檔只對有一定的Maven使用基礎的人有效,我也不會說的太具體,主要是一些配置和注意點。還有本文所用環境是Maven3,并不保證Maven2都能夠成功運行。不好意思,沒有太多時間來測試環境。

           

          一、本地倉庫

          使用 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 遠程倉庫

          2.1 第一種方案 使用wagon-webdav來遠程上傳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>

           

          注意點

           

          1.repo url dav: ...

          2.其他project or module 依賴使用的時候, 請加上 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來遠程上傳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>

           

          注意點

          1.repo url
          svn: ...
          2.
          其他project or module 依賴使用的時候, 請加上 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.好像有個權限認證的問題,會有選擇,選擇最后一項 p: (p)ermanently(永久)應該是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?

           

          個人感覺使用wagon-svn沒有使用wagon-webdav deploy 快,可能是使用協議的問題。

           

          2.3 第三種方案(這才是遠程)

          上面的兩種方法,都必須要配置 repository,如果是普通用戶,并不會關注到這些倉庫配置,當他們不配置這些倉庫URL的,又想使用你的Jar,可否?能否直接使用 group id + artifactId + version 就能依賴到了,答案是肯定的。使用 OSS Sonatype一個代理 Repository,過一段時間會更新到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

                                                                                      

          這種方法,需要等待許許時間,需要Juven Xu進行”bug fix”,開通后,需要和Juven進行交流,完畢后,就可以部署你的ArtifactsOSS Repo里面,最后一步,會進行激活同步到中央倉庫(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/

          clip_image002

          好了,現在你就可以通過下面的配置直接依賴我的Jar包了,不需要配置額外的repo。

                  <dependency>

                      <groupId>com.googlecode.usc</groupId>

                      <artifactId>filename-batch-converter-main</artifactId>

                      <version>3.0.8</version>

                  </dependency>

           

          注意點:

          1.命名盡量以 com.googlecode. 開頭,比如 com.googlecode.usc

          參考 https://docs.sonatype.org/display/Repository/Choosing+your+Coordinates

          2. Maven Release Plugin 使用最新版可能有些問題,建議使用2.0-beta-8 ,我用這個已經成功release到遠程

          3.還是Maven Release Plugin的問題,SVN 的路徑盡量保持規范,即 trunk,tags, brances

          4.這個過程可能有點點漫長,希望大家耐心等待,還有說是兩個小時同步一次,但是據我使用,感覺沒有,可能是一個假象吧,不過能夠使用,結局還是很歡喜的。

           

             使用這種方法請感謝Juven Xu,是他的幫助使我們更加快捷高效地使用Maven,讓共享成為一種樂趣。

           

             上面的所有配置,你都可以在我的google code中找到,你可以通過下面的URLSVN 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

            主要是這個pom配置文件。還有這個project中還有一些其它好玩的東西(比如打包,如何生成exe文件等。),應該會在后面進行分享。

           

          如果有什么建議或意見可以通過微博 http://weibo.com/lishunli(左上側直接加關注)或QQ506817493QQ白天經常不在線,建議微博交流,謝謝),大家一起交流學習。


          最后弱弱地說一下,如果可以的話,轉載請提供原URL。謝謝。

           

          201197

          李順利



          博客中的一些下載已經放到了百度云了,請根據需要下載。【點我去百度云下載】

          最后弱弱地說一下,如果可以的話,轉載請提供出處( ),謝謝。
          posted on 2011-09-07 00:46 李順利 閱讀(5715) 評論(0)  編輯  收藏 所屬分類: Maven

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 丹东市| 光泽县| 社会| 达州市| 呼玛县| 彰武县| 苍溪县| 怀仁县| 忻城县| 泸水县| 崇仁县| 都安| 扎鲁特旗| 大邑县| 高陵县| 博罗县| 镇远县| 增城市| 新干县| 无为县| 乌拉特后旗| 内江市| 洮南市| 色达县| 高邮市| 古交市| 南江县| 金山区| 宜宾市| 阜平县| 固始县| 西和县| 东辽县| 会昌县| 六枝特区| 永靖县| 石河子市| 抚顺市| 紫金县| 原阳县| 武隆县|