Alexander Mills
Alexander Mills

Reputation: 100386

How to use custom url instead of Maven Central for sourcing dependencies

Say I am hosting a JAR file on a url like:

https://raw.githubusercontent.com/async-java/jars/master/x.jar

How can I tell Maven to use this url instead of the default (to Maven Central)?

<dependencies>
  <dependency>
     <groupId>com.my</groupId>
     <artifactId>commons-deps</artifactId>
     <type>pom</type>
  </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>...</groupId>
            <artifactId>...</artifactId>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

I assume somewhere in one of those xml configs we can tell Maven to use the above URL for it? Anybody know the right way to do this?

If it wasn't clear - I don't want to host an entire Maven Repository - I just want to serve a .jar file.

Upvotes: 0

Views: 2823

Answers (2)

J Fabian Meier
J Fabian Meier

Reputation: 35853

You can have different URLs for jars -- but these URLs need to host Maven repositories.

The standard way to add further repositories (in addition to the implicitly present MavenCentral) is to add them to the settings.xml. It is also possible to add them to the POM itself.

A Maven repositories does not have to be a Nexus/Artifactory. It is important, though, that the URL reflects groupId, artifactId, version etc. in the standard manner.

Upvotes: 2

user3000780
user3000780

Reputation: 31

I use this in my pom.xml to reference a shared maven repository that is not maven central.

<repositories>
    <repository>
        <id>my.maven.repository</id>
        <url>https://mymavenrepo.com/jars/location</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>

Upvotes: 1

Related Questions