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>

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

另外插播一个小技巧,我们在配置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>
     

猜你喜欢

转载自blog.csdn.net/tushuping/article/details/107361621