Maven version management with Nexus
2016-04-14 16:53
302 查看
Mavenautodeployandreleaseartifacts,managementtheversion.Mavenhelpyoutoavoidmanuallymodifytheprojectversionandstrictwiththestandardversionpolicy.
NexusRepository
MavenClient
GitClient
EclipsewithMaven,Gitpluginsinstalled
Executeinstall-nexus.batandstart-nexus.batunder%Nexus-Home%\bin\jsw\windows-x86-64inconsole.Note:setupnexusversionis2.12.1.Nexus3usedirectlyinstaller.
OpenNexushomepagehttp://localhost:8081/nexus.Loginuseadmin/admin123.ThereshouldbehavesetPublish,Centerreleases,Snapshotsrepository.AndMakesuretherepositorystatusis"InService".
AddApacheReleaseproxyrepository.SetRemoteStorageLocationashttps://repository.apache.org/content/repositories/releases/
MovetheApacheReleaseRepositorytoOrderedGroupRepositoriesinConfigurationofPublicRepositories.
Note:Ifyoumeetbelowexceptionscausetotheproxyrepositoryunavailableorunreachable,Pleasetrythefollowingsolutions.
ProxyRepositoryunreachablefault.PleaseaddwebproxyhostandportunderNexusMenu---Administration->Server->DefaultHTTPProxySettings
Sun.Security.Validator.ValidatorException:PKIXpathbuildingfailedSun.Security.Validator.ValidatorException:unabletofindvalidcertifactionpathtorequesttarget.
Firstopentheremoteproxyrepositoryinbrowserandexportthecertificationfile.e.g.Maven.cer.
SecondChecktheenabledJVMpath.OpenControlPanel->Java->Javatab->Viewasfollow.
ThirdimportthecertificationtotheJREkeystores.Openconsolerunasadministrator.Changepathto%JRE_HOME%\lib\security.
Executecommand---"keytool-import-trustcacerts-keystorecacerts-aliasMavenRepository-fileMaven.cer"anddefaultpasswordchangeit
SetupSCMMANAGER
Createonegitrepositoryandmarkthepublicselected.e.gCreateoneMavenTestrepository.
MavenandprojectConfigurations
SetMavenuselocalnexusrepositories,configurethemirrorURLelementpointtonexusrepositoryin.m2/settings.xml
mirrorsseeting
2.Addnexusserveruser/password.Thereisuseplaintextpassword,It'salsosupportencryptedtext.
server
3.CreateMavenprojectineclipse:
File->New->MavenProject.Setgroup,artifact,version.
4.Configurescmconnectionsinpom.xml.Thepropertieprojects.scm.idmappingtothescmservercredentialinmavensettings.xml.
scm
5.Addscmcredentialinsettings.xml.
scmserver
6.Inordertodeploytheartifacttonexusrepository.It'sneedspecificthedeployplugin.Forbettermakemavenworkwithnexus.Sonatypecreatenexus-staging-maven-plugin.Ithavebetterfeaturethanmavendefaultdeployplugin.DetailsrefertoNexusStagingMavenPlugin.Duetousenexusdeployplugin.Weneedtoskipthemavendefaultdeployplugin.
nexusdeployplugin
7.Configuremavenreleaseplugin.Itwillreleaseartifacttonexusreleaserepository.Changethepomversioninlocalandscm.updatetheprojectversion.
Mavenreleaseplugin
InitializethelocalGitrepositoryandpushtoSCM
Changethepathtoprojectdirectoryinconsole.Executegitcommandasfollow.
pushexistprojecttogitserver
Prerequisite
SCMMANAGERNexusRepository
MavenClient
GitClient
EclipsewithMaven,Gitpluginsinstalled
Step-by-stepguide
ConfigureNexusRepositoryManagerOSSExecuteinstall-nexus.batandstart-nexus.batunder%Nexus-Home%\bin\jsw\windows-x86-64inconsole.Note:setupnexusversionis2.12.1.Nexus3usedirectlyinstaller.
OpenNexushomepage
AddApacheReleaseproxyrepository.SetRemoteStorageLocationas
MovetheApacheReleaseRepositorytoOrderedGroupRepositoriesinConfigurationofPublicRepositories.
Note:Ifyoumeetbelowexceptionscausetotheproxyrepositoryunavailableorunreachable,Pleasetrythefollowingsolutions.
ProxyRepositoryunreachablefault.PleaseaddwebproxyhostandportunderNexusMenu---Administration->Server->DefaultHTTPProxySettings
Sun.Security.Validator.ValidatorException:PKIXpathbuildingfailedSun.Security.Validator.ValidatorException:unabletofindvalidcertifactionpathtorequesttarget.
Firstopentheremoteproxyrepositoryinbrowserandexportthecertificationfile.e.g.Maven.cer.
SecondChecktheenabledJVMpath.OpenControlPanel->Java->Javatab->Viewasfollow.
ThirdimportthecertificationtotheJREkeystores.Openconsolerunasadministrator.Changepathto%JRE_HOME%\lib\security.
Executecommand---"keytool-import-trustcacerts-keystorecacerts-aliasMavenRepository-fileMaven.cer"anddefaultpasswordchangeit
SetupSCMMANAGER
Createonegitrepositoryandmarkthepublicselected.e.gCreateoneMavenTestrepository.
MavenandprojectConfigurations
SetMavenuselocalnexusrepositories,configurethemirrorURLelementpointtonexusrepositoryin.m2/settings.xml
mirrorsseeting
<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.Addnexusserveruser/password.Thereisuseplaintextpassword,It'salsosupportencryptedtext.
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.CreateMavenprojectineclipse:
File->New->MavenProject.Setgroup,artifact,version.
4.Configurescmconnectionsinpom.xml.Thepropertieprojects.scm.idmappingtothescmservercredentialinmavensettings.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.Addscmcredentialinsettings.xml.
scmserver
<server>
<id>my-scm-server</id>
<username>scmadmin</username>
<password>scmadmin</password>
</server>
6.Inordertodeploytheartifacttonexusrepository.It'sneedspecificthedeployplugin.Forbettermakemavenworkwithnexus.Sonatypecreatenexus-staging-maven-plugin.Ithavebetterfeaturethanmavendefaultdeployplugin.Detailsreferto
nexusdeployplugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version><!--Replacetheversionasyoulocalmavenused,Couldgetitineclipse.openpom.xmluseeditor,clickeffectivePOM-->
<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.Configuremavenreleaseplugin.Itwillreleaseartifacttonexusreleaserepository.Changethepomversioninlocalandscm.updatetheprojectversion.
Mavenreleaseplugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<serverId>releases</serverId>
<!--<tagNameFormat>v@{project.version}</tagNameFormat>-->
</configuration>
</plugin>
InitializethelocalGitrepositoryandpushtoSCM
Changethepathtoprojectdirectoryinconsole.Executegitcommandasfollow.
pushexistprojecttogitserver
$gitinit
#initializethegitproject
$gitadd.
#trackallfilesexcludetargetfolder.youcanaddtargetfolderto.gitignore.detailsreferto'target='_blank'>https://help.github.com/articles/ignoring-files/[/code] $gitcommit-m"Initializethegitproject"$gitremoteaddorigin'target='_blank'>http://ip:8080/scm/git/MavenTest[/code] #addremoteoriginmasterrepository$gitpushoriginmaster#pushlocalchangefilestoremoteoriginmaster.Thengotoscmtochecktheremotesourcesifexistasexcepted.
Deployartifacttonexussnapshots
NowwilldeploytheprojecttoNexusrepository.Theprojectdefaultversionis0.0.1-SNAPSHOT.Whendeploythesnapshotproject.Innexusitwillappendthetimestamptotheendofartifactname.
Executemvncleaninstallinprojectconsole.Itwillinstallartifacttolocalrepositoryin%user_home%\.m2\repository.
Executemvndeploy.Itwilltransfertheartifacttonexusrepository.
ReleaseartifacttoNexusrelease
Beforeexecutereleasecommand.Makesureallthechangefilespushtoscm.Themavenwillautocomputetheversionartifactbyformerartifactversion.Andalteryouifneedtochange.
1.FirstExecutemvnrelease:prepare.Releasepreparewillmodifytheartifactversionintempfolder.andaddgittagintemp.Synchronizewithgitscm.
2.WhenconsoledisplayBUILDSUCCESSinfo.Executemvnrelease:perform.Releaseperformuploadtheartifacttonexusreleaserepository.Youwillseefollowinfodisplayinconsole.Inpom.xmltheartifactversionwillautochangetonextsnapshotversion.
Releaseperform
[INFO]Uploaded:http://localhost:8081/nexus/content/repositories/releases/gdc/MavenTest/0.0.2/Maven
Test-0.0.2-javadoc.jar(23KBat154.7KB/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(3KBat18.7KB/sec)
[INFO][INFO]*Bulkdeployoflocallygatheredsnapshotartifactsfinished.
[INFO][INFO]Remotedeployfinishedwithsuccess.
[INFO][INFO]------------------------------------------------------------------------
[INFO][INFO]BUILDSUCCESS
[INFO][INFO]------------------------------------------------------------------------
[INFO][INFO]Totaltime:02:28min
3.Checkthenexusreleaserepository.Itwilldisplaythereleaseartifactversionasfollowsnapshot.
Nowtheversionwillbemanagementbymaven.Youcandeploythesnapshot.Releaseformalartifactversionloops.
Note:Ifyoumeetbelowerror:justcopythemvn.cmdtomvn.batundermavenbinfolder.
[ERROR]Failedtoexecutegoalorg.apache.maven.plugins:maven-release-plugin:2.5.1:prepare(default-cli)onprojectMave
nTest:FailedtoinvokeMavenbuild.Errorconfiguringcommand-line.Reason:Mavenexecutablenotfoundat:C:\ProgramF
iles\apache-maven-3.3.9\bin\mvn.bat->[Help1]
相关文章推荐
- 计算机相关专业同学如何做好职业规划,选择什么样的方向来发展?
- Volley的网络请求实例
- CAlayer层的属性
- 《MFC 笔记》 Part3 c++的格式.hpp
- 一个c++封装的zookeeper库
- 十个随机数求和 1044 郑明雨
- html css 伪样式
- GDI & GDI+
- R绘图字体解决方案(转)
- 对象的克隆
- JAVA多线程学习笔记
- logstash2.2.0过滤tomcat日志
- 初入程序员的某一天
- Android活动的四种启动方式(standard singleTop singleTask singleInstance)
- Spring中的Mybatis基础
- cocos2d-x 3.4 eclipse android 编译是出现WindowsError: [Error 5] 的解决方法 assets
- TimesTen 应用层数据库缓存学习:6. Aging策略
- TimesTen 应用层数据库缓存学习:5. 异步读写缓存
- UIAutomator测试工具的配置以及使用
- dispatch_sync死锁问题研究