25
votes

I am using nexus open source as my repository manager for Maven 3.0.3

Maven is able to create artifact *.jar.

Now, I would like to know how I can push the generated artifact *.jar to the nexus repo manager, so that other dependent modules can pull from it.

I referred to this guide.

In settings.xml, I have

    <server>     
            <id>nexus-site</id>
            <username>admin</username>
            <password>xxxx</password>
    </server>

It fails.

How can invoke my deployment from mvn command or how to deploy my artifact on to my nexus?

4
What do you mean It fails? What command did you try and what error did you get? - Raghuram
The link to the guide says to put the repo username/password in ~/.m2/repository/settings.xml. I found I had to have settings.xml in ~/.m2 to get it to work. - Alper Akture

4 Answers

27
votes

Just try

   mvn deploy

that will deploy your artifact to the nexus repo manager.

Have you configured the distributionManagement section ?

10
votes

And if you want to add it to the snapshot repository, you need the following configuration inside your pom.xml

<distributionManagement>
    <repository>
         <id>nexus-site</id>
         <name>MyCo Internal Repository</name>
         <url>http://Nexus url</url>
    </repository>
    <snapshotRepository>
         <id>nexus-site</id>
         <name>Your Snapshot Repository</name>
         <url>http://Nexus url</url>
    </snapshotRepository>
</distributionManagement>
4
votes

There are two ways to do so.

The first is do it via Nexus web interface, just upload the artifact with necessary project information (groupId, artifactId, version)

The other is using mvn deploy. You need to set distributionManagement for repository to upload to, and user to authenticate as.

The second approach is strongly recommended if you are going it do deployment regularly. It is automated, and you can leverage on other Maven commands like mvn release

4
votes

Repository element should also be specified. Snippet:pom.xml

<distributionManagement>
    <repository>
      <id>internal.repo</id>
      <name>MyCo Internal Repository</name>
      <url>http://Nexus url</url>
    </repository>
  </distributionManagement>