Maven version management with Nexus

Maven auto deploy and release artifacts, management the version. Maven help you to avoid manually modify the project version and strict with the standard version policy.

Prerequisite

  • SCMMANAGER
  • Nexus Repository
  • Maven Client
  • Git Client
  • Eclipse with Maven, Git plugins installed

Step-by-step guide

Configure Nexus Repository Manager OSS
  1. Execute install-nexus.bat and start-nexus.bat under %Nexus-Home%\bin\jsw\windows-x86-64 in console. Note: setup nexus version is 2.12.1. Nexus 3 use directly installer.
  2. Open Nexus home page http://localhost:8081/nexus . Login use admin/admin123.  There should be have set Publish, Center releases, Snapshots repository. And Make sure the repository status is "In Service".
  3. Add Apache Release proxy repository. Set Remote Storage Location as https://repository.apache.org/content/repositories/releases/
  4. Move the Apache Release Repository to Ordered Group Repositories in Configuration of Public Repositories.

Note: If you meet below exceptions cause to the proxy repository unavailable or  unreachable, Please try the following  solutions.

Proxy Repository unreachable  fault. Please add web proxy host and port under Nexus Menu---Administration->Server->Default HTTP Proxy Settings

Sun.Security.Validator.ValidatorException:PKIX path building failed Sun.Security.Validator.ValidatorException: unable to find valid certifaction path to request target.

First open the remote proxy repository in browser and export the certification file. e.g. Maven.cer .

Second Check the enabled JVM path. Open Control Panel->Java->Java tab->View as follow.

Third import the certification to the JRE key stores. Open console run as administrator. Change path to %JRE_HOME%\lib\security.

Execute command--- "keytool -import -trustcacerts -keystore cacerts -alias MavenRepository -file Maven.cer" and default password changeit

Setup SCMMANAGER
  1. Create one git repository and mark the public selected. e.g Create one MavenTest repository.

Maven and project Configurations
  1. Set Maven use local nexus repositories, configure the mirror URL element point to nexus repository in .m2/settings.xml

mirrors seeting

<mirrors>        
         <mirror>           
         <id>releases</id>           
         <mirrorOf>*</mirrorOf>           
         <url>http://localhost:8081/nexus/content/groups/public/</url>         
         </mirror>        
         <mirror>           
         <id>nexus-snapshots</id>          
         <mirrorOf>*</mirrorOf>           
         <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>         
         </mirror>        
</mirrors>   

2.  Add nexus server user/password. There is use plain text password, It‘s also support encrypted text.

server

<servers>         
    <server>         
         <id>releases</id>        
         <username>admin</username>         
         <password>admin123</password>      
    </server>      
    <server>        
        <id>nexus-snapshots</id>        
        <username>admin</username>      
        <password>admin123</password>      
    </server>
</servers>    

3. Create Maven project in eclipse:

File->New->Maven Project.Set group , artifact, version.

4. Configure scm connections in pom.xml. The propertie projects.scm.id mapping to the scm server credential in maven settings.xml.

scm

<properties>     
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>     
         <project.scm.id>my-scm-server</project.scm.id>   
</properties>
<scm>    
         <url>http://ip:8080/scm/git/MavenTest</url>    
         <connection>scm:git:http://ip:8080/scm/git/MavenTest</connection>    
         <developerConnection>scm:git:http://ip:8080/scm/git/MavenTest</developerConnection>        
</scm>

5. Add scm credential in settings.xml.

scm server

<server>  
   <id>my-scm-server</id>  
   <username>scmadmin</username>  
   <password>scmadmin</password>  
</server>

6. In order to deploy the artifact to nexus repository. It‘s need specific the deploy plugin. For better make maven work with nexus. Sonatype create nexus-staging-maven-plugin. It have better feature than maven default deploy plugin. Details refer to Nexus Staging Maven Plugin. Due to use nexus deploy plugin. We need to skip the maven default deploy plugin.

nexus deploy plugin

 <plugin>     
         <groupId>org.apache.maven.plugins</groupId>     
         <artifactId>maven-deploy-plugin</artifactId>     
         <version>2.7</version>     <!--Replace the version as you local maven used, Could get it in eclipse. open pom.xml use editor, click effective POM -->
         <configuration>        
         <skip>true</skip>     
         </configuration>  
</plugin>  
<plugin>     
         <groupId>org.sonatype.plugins</groupId>     
         <artifactId>nexus-staging-maven-plugin</artifactId>     
         <version>1.3</version>     
         <executions>        
         <execution>           
             <id>default-deploy</id>           
             <phase>deploy</phase>           
             <goals>              
             <goal>deploy</goal>           
            </goals>        
         </execution>     
         </executions>     
         <configuration>        
             <serverId>nexus-snapshots</serverId>        
             <nexusUrl>http://localhost:8081/nexus/</nexusUrl>        
             <skipStaging>true</skipStaging>     
         </configuration>  
</plugin>

7. Configure maven release plugin. It will release artifact to nexus release repository. Change the pom version in local and scm. update the project version.

Maven release plugin

 <plugin>    
         <groupId>org.apache.maven.plugins</groupId>    
         <artifactId>maven-release-plugin</artifactId>    
         <version>2.5.1</version>    
         <configuration>     
         <serverId>releases</serverId> 
         <!--      <tagNameFormat>[email protected]{project.version}</tagNameFormat> -->    
         </configuration>      
</plugin> 
Initialize the local Git repository and push to SCM

Change the path to project directory in console. Execute git command as follow.

push exist project to git server

$git init
#initialize the git project
 
$git add .
#track all files exclude target folder. you can add target folder to .gitignore. details refer to https://help.github.com/articles/ignoring-files/
 
$git commit -m "Initialize the git project"
 
$git remote add origin http://ip:8080/scm/git/MavenTest
#add remote origin master repository
 
$git push origin master
#push local change files to remote origin master. Then go to scm to check the remote sources if exist as excepted.
Deploy artifact to nexus snapshots

Now will deploy the project to Nexus repository. The project default version is 0.0.1-SNAPSHOT. When deploy the snapshot project. In nexus it will append the timestamp to the end of artifact name.

  1. Execute mvn clean install  in project console. It will install artifact to local repository in %user_home%\.m2\repository.
  2. Execute mvn deploy . It will transfer the artifact to nexus repository.
Release artifact to Nexus release

Before execute release command. Make sure all the change files push to scm.The maven will auto compute the version artifact by former artifact version. And alter you if need to change.

1. First Execute mvn release:prepare . Release prepare will modify the artifact version in temp folder. and add git tag in temp. Synchronize with git scm.

2. When console display BUILD SUCCESS info. Execute mvn release:perform .  Release perform upload the artifact to nexus release repository. You will see follow info display in console. In pom.xml the artifact version will auto change to next snapshot version.

Release perform

[INFO] Uploaded: http://localhost:8081/nexus/content/repositories/releases/gdc/MavenTest/0.0.2/Maven

Test-0.0.2-javadoc.jar (23 KB at 154.7 KB/sec)

[INFO] Uploading: http://localhost:8081/nexus/content/repositories/releases/gdc/MavenTest/0.0.2/Mave

nTest-0.0.2-sources.jar

[INFO] Uploaded: http://localhost:8081/nexus/content/repositories/releases/gdc/MavenTest/0.0.2/Maven

Test-0.0.2-sources.jar (3 KB at 18.7 KB/sec)

[INFO] [INFO]  * Bulk deploy of locally gathered snapshot artifacts finished.

[INFO] [INFO] Remote deploy finished with success.

[INFO] [INFO] ------------------------------------------------------------------------

[INFO] [INFO] BUILD SUCCESS

[INFO] [INFO] ------------------------------------------------------------------------

[INFO] [INFO] Total time: 02:28 min

3. Check the nexus release repository . It will display the release artifact version as follow snapshot.

Now the version will be management by maven. You can deploy the snapshot. Release formal artifact version loops.

Note: If you meet below error: just copy the mvn.cmd to mvn.bat under maven bin folder.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.1:prepare (default-cli) on project Mave

nTest: Failed to invoke Maven build. Error configuring command-line. Reason: Maven executable not found at: C:\Program F

iles\apache-maven-3.3.9\bin\mvn.bat -> [Help 1]

时间: 2024-08-16 19:54:46

Maven version management with Nexus的相关文章

使用 Maven 部署 artifact 到 Nexus 教程

本文侧重讲解如何将已经按照好的 Maven 和 Nexus 连接,即如何通过 Maven 部署 artifact 到 Nexus. 本文前提: 1. 安装好 Maven.可以使用 Maven 创建.打包项目.关于安装 2. 安装好 Nexus.可以访问本地的 Nexus 仓库 http://localhost:8081/nexus/#welcome . 正文: 1. 配置 Maven 的配置文件 settings.xml 和 项目的说明文件 pom.xml ,使得 Maven 知道往哪里部署 ,

Maven项目部署到Nexus Repository

(一)下载并安装Nexus Nexus只需下载war包放到tomcat服务器上便可. (二)配置Nexus Repository 打开WEB管理界面:http://localhost:8081/nexus/index.html 点击右上角Log In进行登录,默认帐号:admin.密码:admin123 点击左侧Repositories项 -> central仓库 -> Configuration -> Download Remote Indexes=True -> Save,表示

抗忙,,建个MAVEN的私服仓库-NEXUS

公司最近需求越来越上轨道,MAVEN的私服仓库-NEXUS构架起来哟.. 参考文档URL: http://www.linuxidc.com/Linux/2011-07/39578p3.htm http://www.cnblogs.com/dingyingsi/p/3776557.html http://blog.csdn.net/kimylrong/article/details/23280155 http://blog.linguofeng.com/archive/2012/08/10/mav

搭建Maven私服(使用Nexus)

搭建私服可以做什么? 1.如果公司开发组的开发环境全部内网,这时如何连接到在互联网上的Maven中央仓库呢? 2.如果公司经常开发一些公共的组件,如何共享给各个开发组,使用拷贝方式吗?如果这样,公共库升级了怎么办? 当然可以解决的问题可能不止上面两点,下面来介绍在Linux中搭建自己的Maven私服,使用Nexus. 一.下载和安装 网址:http://www.sonatype.org/nexus/go/ 下载包:nexus-2.12.0-01-bundle.tar.gz 解压包:tar -zx

Maven本地仓库和Nexus仓库不要设为同一个路径

我曾尝试这将Maven本地仓库和Nexus的central仓库设置为同一个目录,这导致Nexus的central仓库被Maven本地仓库覆盖掉了,如果仅仅在本机使用,还凑合着能用,不过central仓库为空,Nexus起不到代理服务的效果.同时如果其它机器使用Nexus来代理仓库服务时,就会报错. 总之,在安装着Nexus的机子上使用Maven,不要妄想着将Maven本地仓库与Nexus仓库合并,企图节约硬盘空间,少一份拷贝.目前来说是不可行的. Maven本地仓库和Nexus仓库不要设为同一个

maven从nexus下载构件以及maven部署构件到nexus的配置

1.maven从nexus下载构件的配置 1.1.在项目pom中配置远程仓库(方式一) <repositories> <repository> <id>remote</id> <name>my nexus repository</name> <url>http://192.1.1.103:8081/nexus/content/groups /public/</url> </repository> &

Maven学习 (四) 使用Nexus搭建Maven私服

为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到这台私服上,这样的话就可以通过这台搭建了nexus私服的电脑访问maven的远程仓库. 1.首先确定我们的环境安装好maven,jdk等必须的环境 2.这些都准备好之后,去下载最新版本的nexus    下载地址:http://www.sonatype.org/nexus/go 我本地安装的是 ne

Maven、eclipse与Nexus私服配置指南

1.1  Maven 1.1.1  相关概念 Maven是一个软件项目管理工具,通过它可便捷的管理项目的生命周期.即项目的jar包依赖,开发,测试,发布打包.版本等.虽然目前的IDE工具(如eclipse)可管理开发.发布.打包工作,但还没有形成一套完成的体系. Maven有以下几个功能特点: 1. jar包依赖 这个也许会maven最突出的特点.使用maven进行开发时,不需要上网单独下载jar包,只需要在配置文件pom.xml中配置jar包的依赖关系,就可以自动下载jar包到我们的项目中(在

Maven教程4(私服-nexus)

仓库管理器也叫私服或代理仓库 仓库管理器有两个服务目的:首先它的角色是一个高度可配置的介于你的组织与公开Maven仓库之间的代理,其次它为你的组织提供了一个可部署你组织内部生成的构件的地方. 1Nexus介绍 Nexus是一个强大的Maven仓库管理器, 它极大地简化了自己内部仓库的维护和外部仓库的访问. 利用Nexus你可以只在一个地方就能够完全控制访问和部署在你所维护仓库中的每个Artifact. Nexus是一套"开箱即用"的系统不需要数据库,它使用文件系统加Lucene来组织数