如何在Maven配置中正确指定jcenter存储库?

23
在Gradle中,我只需要添加以下内容:
  repositories {  
   jcenter()  
  }

在Maven的pom.xml文件中,最简单和正确的方式是什么,或者我在哪里可以获得正确的JCenter仓库URL?


你可以使用这个settings.xml示例。你可以将其作为参考 - Royg
3个回答

27

您需要像以下这样定义settings.xml。如果您将其定义在~/.m2/settings.xml中,则它将对您的Maven全局生效。如果您将其定义为项目的资源,您可以使用-s参数绑定:

mvn -s settings.xml compile

<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
          xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
    
    <profiles>
        <profile>
            <repositories>
                <repository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>central</id>
                    <name>bintray</name>
                    <url>https://jcenter.bintray.com</url>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>central</id>
                    <name>bintray-plugins</name>
                    <url>https://jcenter.bintray.com</url>
                </pluginRepository>
            </pluginRepositories>
            <id>bintray</id>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>bintray</activeProfile>
    </activeProfiles>
</settings>


1
截至2020年6月,JCenter仅支持HTTPS。因此,这里的URL地址必须更改为https。 - aydinugur

23

只需在您的pom文件中添加一个repositories部分:

<repositories>
    <repository>
        <id>jcenter</id>
        <name>jcenter</name>
        <url>https://jcenter.bintray.com</url>
    </repository>
</repositories>

URL可以从存储库页面的右上角复制。例如,Spring releases repositoryhttps://dl.bintray.com/spring/jars Maven存储库URL。 - Ilya Serbis

13

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接