Jason Corbett
Jason Corbett

Reputation: 109

Build and Deploy a Maven Project to Nexus via Jenkins

I have configured a simple maven freestyle project. I was able to successfully build the project but not deploy to Nexus. I get this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.1:deploy (default-deploy) on project eqs_utility: Failed to deploy artifacts: Could not find artifact com.companyName.eqs:eqs_utility:jar:1.0.1-20190529.191240-1 in nexus (https://nexus.companyRepo.com/repository/maven-snapshot/) -> [Help 1]

I have tried to change configurations to simplify the project but still nothing. Setting.xml changes.

EDITED I added the following to my POM.xml

    <distributionManagement>
        <repository>
            <uniqueVersion>false</uniqueVersion>
            <id>nexus</id>
            <name>Company Nexus Repository</name>
            <url>https://nexus.mycompany.com/repository/maven-release/</url>
            </repository>    
        <snapshotRepository>
            <uniqueVersion>true</uniqueVersion>
            <id>nexus</id>
            <name>Company Nexus Snapshots</name>
            <url>https://nexus.companyName.com/repository/maven-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>

Then, updated my settings.xml with this

<server>
      <id>nexus</id>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>


    <!-- Another sample, using keys to authenticate. -->
    <server>
      <id>nexus</id>
      <username>NexusUser</username>
      <password>MyLongTokenValueHere</password>
    </server>

Upvotes: 0

Views: 1873

Answers (1)

Ian W
Ian W

Reputation: 4767

According to Apache Maven Deploy Plugin setup

You need a section:

  <distributionManagement>
    <repository>
      <id>internal.repo</id>
      <name>MyCo Internal Repository</name>
      <url>Host to Company Repository</url>
    </repository>
  </distributionManagement>

As you're using Nexus, you probably need a section in the pom that aligns with your nexus repositories (one for snapshots and one for release artifacts since you can't combine them in nexus):

<distributionManagement>
   <repository>
      <id>mavenrepository</id>
      <url>http://mavenrepository.companyName.com/nexus/content/repositories/m3</url>
   </repository>
   <snapshotRepository>
      <id>tmavenrepository</id>
      <url>http://mavenrepository.companyName.com/nexus/content/repositories/m3-snapshots</url>
   </snapshotRepository>
</distributionManagement>

Plus of course, in your local settings or other private location

    <server>
      <id>mavenrepository</id>
      <username>maven</username>
      <password>foobar</password>
    </server>

This is described by Sonatype and cleaner by others.

Upvotes: 1

Related Questions