Maven Central serves as the central repository manager where binary artifacts are uploaded by different teams/companies/individuals and shared with rest of the world. Much like github, and other source code repositories, which are very effective for source code control, these repository managers also act as a deployment destination for your own generated binary artifacts.
Setting up a local repository manager has several advantages. The primary ones are that they act as a highly configurable proxy between Maven central so that everybody does not have to download all the dependencies from the central repo. Another primary reason is to control your interim generated artifacts within your team. Reasons to Use a Repository Manager provide detailed explanation of a complete set of benefits.
This Tech Tip will show how to setup a local Nexus repository manager, and push artifacts to it – both snapshots and releases.
Lets get started!
Install and Configure Local Nexus Repository
- Download and unzip latest Nexus OSS. Default administrator’s login/password is admin/admin123. Default deployment login/password is deployment/deployment123.
- Start up Nexus as:
12345nexus-2.11.2-03> ./bin/nexus startStarting Nexus OSS...Started Nexus OSS.
123nexus-2.11.2-03> tail -f logs/wrapper.log
12345678910111213141516nexus-2.11.2-03> ./bin/nexus consoleRunning Nexus OSS...wrapper | --> Wrapper Started as Consolewrapper | Launching a JVM...jvm 1 | Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=192m; support was removed in 8.0jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.orgjvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.jvm 1 |. . .jvm 1 | 2015-02-24 00:17:28,706-0800 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Runningjvm 1 | 2015-02-24 00:17:28,706-0800 INFO [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Startedjvm 1 | 2015-02-24 00:17:30,713-0800 INFO [ar-4-thread-3] *SYSTEM org.sonatype.nexus.proxy.maven.routing.internal.ManagerImpl - Updated and published prefix file of "Public Repositories" [id=public] - Configure Maven Settings file (~.m2/settings.xml) to include the default deployment username and password as:
123456789101112<?xml version="1.0" encoding="UTF-8" standalone="no"?><settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"><servers><server><id>deployment</id><username>deployment</username><password>deployment123</password></server></servers></settings>
Deploy Snapshot to Local Nexus Repository
- Check out a simple Java EE sample from github.com/javaee-samples/javaee7-simple-sample.
- Create and deploy the WAR file to the local Nexus repository as:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697javaee7-simple-sample> mvn deploy[INFO] Scanning for projects...[INFO][INFO] ------------------------------------------------------------------------[INFO] Building javaee7-simple-sample 1.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO][INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ javaee7-simple-sample ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] Copying 0 resource[INFO][INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ javaee7-simple-sample ---[INFO] Changes detected - recompiling the module![INFO] Compiling 4 source files to /Users/arungupta/workspaces/javaee7-simple-sample/target/classes[INFO][INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ javaee7-simple-sample ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /Users/arungupta/workspaces/javaee7-simple-sample/src/test/resources[INFO][INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ javaee7-simple-sample ---[INFO] No sources to compile[INFO][INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ javaee7-simple-sample ---[INFO] No tests to run.[INFO][INFO] --- maven-war-plugin:2.3:war (default-war) @ javaee7-simple-sample ---[INFO] Packaging webapp[INFO] Assembling webapp [javaee7-simple-sample] in [/Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample][INFO] Processing war project[INFO] Copying webapp resources [/Users/arungupta/workspaces/javaee7-simple-sample/src/main/webapp][INFO] Webapp assembled in [33 msecs][INFO] Building war: /Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample.war[INFO][INFO] --- maven-install-plugin:2.4:install (default-install) @ javaee7-simple-sample ---[INFO] Installing /Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample.war to /Users/arungupta/.m2/repository/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-SNAPSHOT.war[INFO] Installing /Users/arungupta/workspaces/javaee7-simple-sample/pom.xml to /Users/arungupta/.m2/repository/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-SNAPSHOT.pom[INFO][INFO] >>> wildfly-maven-plugin:1.0.2.Final:deploy (default) > package @ javaee7-simple-sample >>>[INFO][INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ javaee7-simple-sample ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] Copying 0 resource[INFO][INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ javaee7-simple-sample ---[INFO] Nothing to compile - all classes are up to date[INFO][INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ javaee7-simple-sample ---[INFO] Using 'UTF-8' encoding to copy filtered resources.[INFO] skip non existing resourceDirectory /Users/arungupta/workspaces/javaee7-simple-sample/src/test/resources[INFO][INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ javaee7-simple-sample ---[INFO] No sources to compile[INFO][INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ javaee7-simple-sample ---[INFO] No tests to run.[INFO] Skipping execution of surefire because it has already been run for this configuration[INFO][INFO] --- maven-war-plugin:2.3:war (default-war) @ javaee7-simple-sample ---[INFO] Packaging webapp[INFO] Assembling webapp [javaee7-simple-sample] in [/Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample][INFO] Processing war project[INFO] Copying webapp resources [/Users/arungupta/workspaces/javaee7-simple-sample/src/main/webapp][INFO] Webapp assembled in [3 msecs][INFO] Building war: /Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample.war[INFO][INFO] <<< wildfly-maven-plugin:1.0.2.Final:deploy (default) < package @ javaee7-simple-sample <<<[INFO][INFO] --- wildfly-maven-plugin:1.0.2.Final:deploy (default) @ javaee7-simple-sample ---Feb 24, 2015 1:02:46 AM org.xnio.Xnio <clinit>INFO: XNIO version 3.2.2.FinalFeb 24, 2015 1:02:46 AM org.xnio.nio.NioXnio <clinit>INFO: XNIO NIO Implementation Version 3.2.2.FinalFeb 24, 2015 1:02:46 AM org.jboss.remoting3.EndpointImpl <clinit>INFO: JBoss Remoting version 4.0.3.Final[INFO][INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ javaee7-simple-sample ---Downloading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/maven-metadata.xmlDownloaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/maven-metadata.xml (783 B at 4.0 KB/sec)Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-20150224.090247-2.warUploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-20150224.090247-2.war (6 KB at 90.4 KB/sec)Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-20150224.090247-2.pomUploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-20150224.090247-2.pom (3 KB at 53.2 KB/sec)Downloading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/maven-metadata.xmlDownloaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/maven-metadata.xml (297 B at 13.8 KB/sec)Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/maven-metadata.xmlUploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/maven-metadata.xml (783 B at 20.7 KB/sec)Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/maven-metadata.xmlUploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/maven-metadata.xml (297 B at 6.7 KB/sec)[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 4.398 s[INFO] Finished at: 2015-02-24T01:02:47-08:00[INFO] Final Memory: 22M/310M[INFO] ------------------------------------------------------------------------The actual repository storage is in
../sonatype-work/nexus
directory. This is created in parallel to where ever Nexus OSS bundle was unzipped.
Deploy Release to Local Nexus Repository
- Clean any previously performed release:
123456789101112131415161718javaee7-simple-sample> mvn release:clean -P release[INFO] Scanning for projects...[INFO][INFO] ------------------------------------------------------------------------[INFO] Building javaee7-simple-sample 1.1-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO][INFO] --- maven-release-plugin:2.5.1:clean (default-cli) @ javaee7-simple-sample ---[INFO] Cleaning up after release...[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 0.912 s[INFO] Finished at: 2015-02-24T02:18:53-08:00[INFO] Final Memory: 10M/245M[INFO] ------------------------------------------------------------------------
- Prepare for the next release:
123456789101112131415161718192021222324252627282930313233343536373839404142434445javaee7-simple-sample> mvn release:prepare -P release[INFO] Scanning for projects...[INFO][INFO] ------------------------------------------------------------------------[INFO] Building javaee7-simple-sample 1.3-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO][INFO] --- maven-release-plugin:2.5.1:prepare (default-cli) @ javaee7-simple-sample ---[INFO] Verifying that there are no local modifications...[INFO] ignoring changes on: **/pom.xml.releaseBackup, **/pom.xml.next, **/pom.xml.tag, **/pom.xml.branch, **/release.properties, **/pom.xml.backup[INFO] Executing: /bin/sh -c cd /Users/arungupta/workspaces/javaee7-simple-sample && git rev-parse --show-toplevel[INFO] Working directory: /Users/arungupta/workspaces/javaee7-simple-sample[INFO] Executing: /bin/sh -c cd /Users/arungupta/workspaces/javaee7-simple-sample && git status --porcelain .[INFO] Working directory: /Users/arungupta/workspaces/javaee7-simple-sample[WARNING] Ignoring unrecognized line: ?? release.properties[INFO] Checking dependencies and plugins for snapshots ...What is the release version for "javaee7-simple-sample"? (org.javaee7.sample:javaee7-simple-sample) 1.3: :What is SCM release tag or label for "javaee7-simple-sample"? (org.javaee7.sample:javaee7-simple-sample) v1.3: :What is the new development version for "javaee7-simple-sample"? (org.javaee7.sample:javaee7-simple-sample) 1.4-SNAPSHOT: :[INFO] Transforming 'javaee7-simple-sample'...[INFO] Not generating release POMs[INFO] Executing goals 'clean verify'...[WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.[INFO] [INFO] Scanning for projects...[INFO] [INFO][INFO] [INFO] ------------------------------------------------------------------------[INFO] [INFO] Building javaee7-simple-sample 1.3[INFO] [INFO] ------------------------------------------------------------------------. . .[INFO] Executing: /bin/sh -c cd /Users/arungupta/workspaces/javaee7-simple-sample && git symbolic-ref HEAD[INFO] Working directory: /Users/arungupta/workspaces/javaee7-simple-sample[INFO] Executing: /bin/sh -c cd /Users/arungupta/workspaces/javaee7-simple-sample && git push https://github.com/javaee-samples/javaee7-simple-sample.git refs/heads/master:refs/heads/master[INFO] Working directory: /Users/arungupta/workspaces/javaee7-simple-sample[INFO] Release preparation complete.[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 01:04 min[INFO] Finished at: 2015-02-24T02:55:59-08:00[INFO] Final Memory: 11M/245M[INFO] ------------------------------------------------------------------------
- Perform the release:
123456789101112131415161718192021javaee7-simple-sample> mvn javadoc:jar source:jar release:perform -P release[INFO] Scanning for projects...[INFO][INFO] ------------------------------------------------------------------------[INFO] Building javaee7-simple-sample 1.4-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO][INFO] --- maven-javadoc-plugin:2.10.1:jar (default-cli) @ javaee7-simple-sample ---. . .[INFO] [INFO] ------------------------------------------------------------------------[INFO] [INFO] BUILD FAILURE[INFO] [INFO] ------------------------------------------------------------------------[INFO] [INFO] Total time: 5.820 s[INFO] [INFO] Finished at: 2015-02-24T02:58:16-08:00[INFO] [INFO] Final Memory: 31M/312M[INFO] [INFO] ------------------------------------------------------------------------[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project javaee7-simple-sample: Failed to deploy artifacts: Could not transfer artifact org.javaee7.sample:javaee7-simple-sample:war:1.3 from/to deployment (http://localhost:8081/nexus/content/repositories/releases/): Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/org/javaee7/sample/javaee7-simple-sample/1.3/javaee7-simple-sample-1.3.war. Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]
Notice, how this command is ending with an error. This is similar to as reported here but the strange thing is that the files are still uploaded on Nexus. Here is the snapshot from localhost:8081/nexus/#view-repositories;releases~browsestorage while trying to test multiple releases and wondering about these “spurious” error messages:
This error will require more debugging but at least snapshot and release builds can now be stored on local Nexus repository.
UPDATE: Manfred Moser helped debug this error by sending pull requests. This error is now gone and instead should show something like:
123456789101112131415161718[INFO] Uploaded: http://localhost:8081/nexus/content/repositories/releases/org/javaee7/sample/javaee7-simple-sample/1.8/javaee7-simple-sample-1.8-sources.jar (3 KB at 74.7 KB/sec)[INFO] [INFO] ------------------------------------------------------------------------[INFO] [INFO] BUILD SUCCESS[INFO] [INFO] ------------------------------------------------------------------------[INFO] [INFO] Total time: 5.673 s[INFO] [INFO] Finished at: 2015-02-26T03:50:18+05:30[INFO] [INFO] Final Memory: 31M/320M[INFO] [INFO] ------------------------------------------------------------------------[INFO] Cleaning up after release...[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 01:10 min[INFO] Finished at: 2015-02-26T03:50:30+05:30[INFO] Final Memory: 13M/245M[INFO] ------------------------------------------------------------------------
You learned how to setup a local Nexus Repository and push snapshot and release builds to it. Subsequent blogs will show how this repository can be used for CI/CD.
Enjoy!
Arun,
Thanks for posting this blog. We would love to cross-post it on TheNexus community pages with full attribution, with your permission. See http://www.sonatype.org/nexus/
If you are interested, let’s coordinate via email. You can reach me at weeks[at]sonatype[dotcom].
Cheers,
Derek
Excelent post congratulation, thank you
If you are having requirement of the ways to product data entry so you the best and exact results you can find here eCommerce Data Entry outsourcing by which you can make your all work easier and can apply systematically. So have a visit for once.