0
votes

I have currently maven, jenkins, Nexus and git integrated and I'm kind of learning these tools.

My requirement is to tell maven to download my dependencies only from the repositories which I have mentioned in my pom.xml and not from my Nexus repository but its doing the opposite.

I have declared my Nexus releases and snapshots repositories under repository in my settings.xml. How do I tell maven to download my dependencies from specific repository and not from my Nexus repo.

Below is my pom.xml snippet

<repositories>
    <repository>
            <id>faq</id>
            <url>https://mycheck.github.com/faq/port/hist</url>
    </repository>

    <repository>
      <id>dig</id>
     <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
   </repository>
</repositories>

<dependencies>
        <dependency>
            <groupId>com.org</groupId>
            <artifactId>faq</artifactId>
            <version>${faq.version}</version>
        </dependency>
        <dependency>
            <groupId>com.net.myorg</groupId>
            <artifactId>retina</artifactId>
            <version>${retina-support.version}</version>
        </dependency>
            ........
            ......
 </dependencies>
2
This can't be done in your pom neither from Maven. This is the job for Nexus. Define the repository their and define appropriate routes in Nexus... - khmarbaise

2 Answers

1
votes

In your pom.xml you have to override the repository configured in settings.xml to disable both snapshots and releases. For example, considering a repository my-repo is configured in your settings.xml that you want to ignore in your project, your pom.xml must contains:

<repositories>
    <repository>
        <id>my-repo</id> <!-- id must match settings.xml -->
        <name>My Private Repo</name>
        <url>http://repo.mycompany.org/maven2</url>
        <layout>default</layout>
        <!-- disable both snapshots and releases -->
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>
</repositories>

The <id> must match the one configured in your settings. As both snapshots and releases are set to false Maven will simply ignore the repository for your project. You must specify each repository you want to ignore this way.

0
votes

I'm not sure i understand, but this can be done in the maven settings.xml file, inside this file you can specify the Repositories policy...

https://confluence.atlassian.com/bamkb/how-to-override-the-maven-local-repository-setting-838546993.html

Moreover the repo can be specified as parameter when you call the maven command you want to run.

This for more ref about the settings.html: https://maven.apache.org/settings.html