发布本地项目和源码到maven私服中

有时候我们会使用第三方包到我们的项目中,但是想看源码的时候,需要下载源码查看,十分麻烦。

不如把源码上传到maven私服中,这样查看源码的时候就可以直接从maven nexus下载直接查看了。

注:nexus 安装参考
http://blog.csdn.net/xiaoreqing/article/details/51742828

方法如下:

1、在setting.xml文件中增加用户名和密码配置(特别注意这里的ID)

<servers>
        <!-- 用于发布正式版本 -->
        <server>
            <id>maven-repository-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <!-- 用于发布快照版本 -->
        <server>
            <id>maven-repository-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>

2、在项目的pom.xml中增加以下内容

<build>
        <plugins>
            <!-- 要将源码放上去,需要加入这个插件 -->
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <repository>
            <!-- 这里的ID要和setting的id一致 -->
            <id>maven-repository-releases</id>
            <url>http://ip:8081/nexus/content/repositories/thirdparty/</url>
        </repository>
        <!--这是打成快照版本的配置,如果不用这个snapshotRepository标签,打包失败,会报权限问题 -->
        <snapshotRepository>
            <id>maven-repository-snapshots</id>
            <url>http://ip:8081/nexus/content/repositories/thirdparty</url>
        </snapshotRepository>
    </distributionManagement>

3.执行Maven build的deploy命令

这里写图片描述

4.如果是替换老版本,可能会出现如下错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project YourProject: Failed to deploy artifacts: Could not transfer artifact YourProject:jar:3.0.1 from/to maven-repository-releases (http://ip:8081/nexus/content/repositories/thirdparty/): Failed to transfer file: http://192.168.16.204:8081/nexus/content/repositories/thirdparty/../../YourProject.jar. Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这是maven deploy 已存在的包的时候出现400错误,原因是 release 默认库是不允许重复部署的。

解决: 修改maven 私服配置.

修改图中配置就可以重复部署了:Deployment Policy:Allow Redeploy
这里写图片描述

5.其他可能遇到的问题

用户权限问题,可能导致发布失败。

本文参考:http://blog.csdn.net/lzzyok/article/details/25626583f

    http://blog.csdn.net/lulongzhou_llz/article/details/42869785

业务驱动技术,技术是手段,业务是目的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值