简体   繁体   中英

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.

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM