Search code examples
mavenrepositorypom.xmlnexusartifact

Check if artifact or dependency exist in a private repository


This is my POM file that generate a JAR artifact and it is stored in a private repository with Nexus Repository

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.home.mac</groupId>
  <artifactId>hyper-dev</artifactId>
  <version>0.0.1</version>
  <build>
    <sourceDirectory>src</sourceDirectory>

    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>  
  </build>

  <dependencies>
    <dependency>
        <groupId>org.home.mac</groupId>
        <artifactId>hyper-test-linux</artifactId>
        <version>0.3.5</version>
    </dependency>
  </dependencies>
</project>

I want to check two things:

  • If the artifact that I am going to install hyper-dev-0.0.1 exists in my private maven repository.
  • If the dependency with artifactID: hyper-test-linux-0.3.5 exists in my private maven repository.

Is it possible?


Solution

  • You can use Nexus' Rest Api to check if an artifact exists.

    For example, the url

    http://<your private nexus server>:8081/service/rest/beta/search/assets?group=org.home.mac&name=hyper-dev&version=0.0.1&maven.extension=jar&maven.classifier
    

    will show you if the artifact hyper-dev in the version 0.0.1 is available in your private Nexus.

    If you want to automate the process, you can use a command line tool like wget or curl to access the Rest Api, as shown in the document linked above.

    Remark: I would like to repeat the comment of khmarbaise that is usually not possible to upload a released artifact to Nexus if it already exists in the repository. If you want to upload it again, you have to increase the version and by doing so, create a new artifact. It would be an unwanted feature to update existing artifacts, as Maven assumes that a downloaded artifact will never change and caches them locally on every machine.

    Snapshot artifacts can actually be updated, but you have asked about released artifacts.