简体   繁体   English

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

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

Say I am hosting a JAR file on a url like: 说我在一个URL上托管一个JAR文件,例如:

https://raw.githubusercontent.com/async-java/jars/master/x.jar 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)? 我怎样才能告诉Maven使用这个URL而不是默认的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>

I assume somewhere in one of those xml configs we can tell Maven to use the above URL for it? 我假设在那些xml配置之一中的某个地方,我们可以告诉Maven使用上面的URL? 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. 如果不清楚-我不想托管整个Maven存储库-我只想提供.jar文件。

You can have different URLs for jars -- but these URLs need to host Maven repositories. 您可以为jars使用不同的URL,但是这些URL需要托管Maven存储库。

The standard way to add further repositories (in addition to the implicitly present MavenCentral) is to add them to the settings.xml . 添加其他存储库(除了隐式存在的MavenCentral之外)的标准方法是将它们添加到settings.xml It is also possible to add them to the POM itself. 也可以将它们添加到POM本身。

A Maven repositories does not have to be a Nexus/Artifactory. Maven存储库不必是Nexus / Artifactory。 It is important, though, that the URL reflects groupId, artifactId, version etc. in the standard manner. 但是重要的是,URL以标准方式反映groupId,artifactId,版本等。

I use this in my pom.xml to reference a shared maven repository that is not maven central. 我在pom.xml中使用它来引用不是Maven中心的共享Maven存储库。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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