您的位置:首页 > 其它

Maven version management with Nexus

2016-04-14 16:53 302 查看

Mavenautodeployandreleaseartifacts,managementtheversion.Mavenhelpyoutoavoidmanuallymodifytheprojectversionandstrictwiththestandardversionpolicy.

Prerequisite

SCMMANAGER

NexusRepository

MavenClient

GitClient

EclipsewithMaven,Gitpluginsinstalled

Step-by-stepguide

ConfigureNexusRepositoryManagerOSS

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

<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.DetailsrefertoNexusStagingMavenPlugin.Duetousenexusdeployplugin.Weneedtoskipthemavendefaultdeployplugin.

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]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: