李顺利
随笔-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 李顺利 阅读(5677) 评论(0)  编辑  收藏 所属分类: Maven

只有注册用户登录后才能发表评论。


网站导航: