强迫 maven 对 maven 中心使用 HTTPS 的正确方法是什么?

2022-09-01 04:51:35

最近,sonatype启用了maven central来支持https(背景信息)。我现在已将以下代码段添加到我的 pom.xml强制在任何地方使用 https:

<!-- force https -->
<repositories>
    <repository>
        <id>central</id>
        <url>https://repo1.maven.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <url>https://repo1.maven.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

问题:

  • 这就够了吗?还是还会在某个地方涉及http?
  • 这是正确的方法吗?正如我所读到的,我应该在设置中执行此操作.xml相反。但是,使用我的(开源)项目的其他人将不会使用安全连接。

更新

它看起来还不够,例如,仍然使用HTTP的汇编插件:

[INFO] --- maven-assembly-plugin:2.4:single (make-assembly) @ graphhopper-web ---
Downloading: http://repo.maven.apache.org/maven2/org/slf4j/slf4j-jdk14/1.5.6/slf4j-jdk14-1.5.6.jar

答案 1

您不必将其逐个放入所有POM中。我宁愿建议将以下代码添加到MAVEN_HOME\conf\settings.xml部分:<profiles>

<profile>
    <id>maven-https</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories> 
</profile>

这将始终是一个活动设置,除非您在需要时在POM中取消/覆盖它。


答案 2

这在最新的 maven 3.2.3 中已经修复!查看更新日志

因此,请安装 maven 3.2.3 并执行 “rm -rf ~/.m2/repository/*” 以获得更好的感觉;)


推荐