maven打包到nexus

一、介绍

maven提供了很多丰富的插件,其中有一个就是maven deploy,具体介绍,大家可以查看官网

http://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html

二、使用

那么如何将代码编译,打包,上传到neuxs呢?

首先,我们需要对maven进行配置,这段配置的意思是配置了一个名字叫release-test-environment的仓库,其代码仓地址为https://192.168.1.1:8081/repository/release-test-environment,并将其激活

 <profiles>
   <profile>
      <id>nexus</id>
      <properties>
        <altDeploymentRepository>release-test-environment::default::https://192.168.1.1:8081/repository/release-test-environment/</altDeploymentRepository>
      </properties>
    </profile>
 </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

当然一般上传仓库需要账号密码,我们为仓库配置其账号密码

<server>
  <id>release-test-environment</id>
  <username>test</username>
  <password>*****</password>
</server>

然后我们直接执行 mvn deploy,就可以将包上传至nexus,如果是maven多模块,就会将所以子模块都会上传至nexus

如果我们同时需要上传到snapshot和trelease,可以配置如下:

<profiles>
    <profile>
      <id>nexus</id>
      <properties>                 
<altSnapshotDeploymentRepository>
snapshots::default::https://dev-nexus-repo:8081/repository/snapshots
</altSnapshotDeploymentRepository>

<altReleaseDeploymentRepository>
releases::default::https://dev-nexus-repo:8081/repository/releases
</altReleaseDeploymentRepository>
      </properties>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

</settings>

这种方式比将构建信息配置在业务代码上来说,减少了重复的配置,业务解耦,所以推荐这种方式

我们在使用altSnapshotDeploymentRepository可能会报错

 Depl
oyment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id
::layout::url parameter -> [Help 1]
这个原因是altSnapshotDeploymentRepository在deploy插件2.8版本后才有效,我们可以强制指定deploy 的版本,就可以使用了

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

另外插播一个小技巧,我们在配置maven镜像时有时候想要配置多个源,如果第一个找不到去第二个找,以此类推,我们可以通过修改   <mirrorOf>central</mirrorOf>的方式来解决,rep1表示备用1号,备胎可以多个

 <mirror>
      <id>central</id>
      <mirrorOf>central</mirrorOf>
      <name>download</name>
      <url>https://dev-nexus-repo:8081/repository/maven-public/</url>
    </mirror>
     
 <mirror>
      <id>rep1</id>
      <mirrorOf>rep1</mirrorOf>
      <name>EC download</name>
      <url>https://dev-nexus-repo:8081/repository/maven-public/</url>
  </mirror>
       
 <mirror>
      <id>rep2</id>
      <mirrorOf>rep2</mirrorOf>
      <name>EC repository download</name>
      <url>https://dev-nexus-repo:8081/repository/maven-public/</url>
    </mirror>
     

 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值