mvn deploy部署到nexus的教程详解

在使用maven构建模块化项目时,将项目打包发布到中央仓库是很频繁的操作,通过配置可以简化这个过程。

settings.xml配置账号密码

<servers>
    <server>
        <id>deploymentRepo</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
    <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
</servers>

直接部署jar包

mvn deploy:deploy-file -DgroupId=com.renhenet -DartifactId=renhesoa-api -Dversion=1.0.0 -Dpackaging=jar -Dfile=target/renhesoa-api-1.0.0.jar -Durl=http://localhost:8083/content/repositories/thirdparty/ -DrepositoryId=deploymentRepo


DrepositoryId即setting.xml中得server.id


扩展:mvn clean deploy -DskipTests #这个命令可以直接把所有依赖包上传到私服上去

使用deploy插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.7</version>
</plugin>

添加deploy插件后,执行mvn deploy会报错,如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project renhesoa-api: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]

提示还需配置distributionManagement,指定DaltDeploymentRepository,如下:

<distributionManagement>
   <repository>
      <id>deploymentRepo</id>
      <name>Nexus Renhe</name>
      <url>http://localhost:8083/content/repositories/thirdparty/</url>
   </repository>
</distributionManagement>

添加源码插件,同步发布源码包

<plugin>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>jar-no-fork</goal>
            </goals>
        </execution>
    </executions>
</plugin>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值