如何使用自定义 url 而不是 Maven Central 来获取依赖项

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

假设我在 url 上托管一个 JAR 文件,例如:

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

如何告诉 Maven 使用此 url 而不是默认值(对 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>

我假设在其中一个 xml 配置中的某处,我们可以告诉 Maven 使用上面的 URL 吗?有人知道这样做的正确方法吗?

如果不清楚 - 我不想托管整个 Maven 存储库 - 我只想提供一个 .jar 文件。

我在 pom.xml 中使用它来引用一个共享的 Maven 存储库,它不是 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>

您可以为 jars 使用不同的 URL——但是这些 URL 需要托管 Maven 存储库。

添加更多存储库(除了隐式存在的 MavenCentral)的标准方法是将它们添加到 settings.xml。也可以将它们添加到 POM 本身。

Maven 存储库不必是 Nexus/Artifactory。不过,重要的是 URL 以标准方式反映 groupId、artifactId、版本等。