linux下maven使用aliyun仓库有问题 不识别证书?

└─$ mvn install
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.xiinnn:CTF-Java-Gadget >---------------------
[INFO] Building CTF-Java-Gadget 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from aliyunmaven-central: https://maven.aliyun.com/repository/central/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.pom
Downloading from aliyunmaven-central: https://maven.aliyun.com/repository/central/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.072 s
[INFO] Finished at: 2024-11-19T08:23:39-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project CTF-Java-Gadget: Could not collect dependencies for project com.xiinnn:CTF-Java-Gadget:jar:1.0-SNAPSHOT
[ERROR] Failed to read artifact descriptor for commons-collections:commons-collections:jar:3.2.1
[ERROR]     Caused by: The following artifacts could not be resolved: commons-collections:commons-collections:pom:3.2.1 (absent): Could not transfer artifact commons-collections:commons-collections:pom:3.2.1 from/to aliyunmaven-central (https://maven.aliyun.com/repository/central): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[ERROR] Failed to read artifact descriptor for commons-collections:commons-collections:jar:3.2.2
[ERROR]     Caused by: The following artifacts could not be resolved: commons-collections:commons-collections:pom:3.2.2 (absent): Could not transfer artifact commons-collections:commons-collections:pom:3.2.2 from/to aliyunmaven-central (https://maven.aliyun.com/repository/central): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

jdk 中的证书。

┌──(kali㉿kali)-[~/…/java-se-8u43-ri/jre/lib/security]
└─$ keytool -list -V  -keystore cacerts -storepass changeit | grep aliyun | more
Alias name: aliyun
Owner: CN=*.aliyun.com, O="Alibaba (China) Technology Co., Ltd.", L=HangZhou, ST=ZheJiang, C=CN
  DNSName: *.aliyun.com
  DNSName: *.aliyun-iot-share.com
  DNSName: *.hologres.aliyuncs.com
  DNSName: *.yuntu.aliyun.com
  DNSName: *.help-ccs.aliyun.com
  DNSName: *.app.aliyun.com
  DNSName: *.rtc.aliyun.com
  DNSName: *.acs-internal.aliyuncs.com
  DNSName: *.cn-hangzhou.aliyuncs.com
  DNSName: *.tw-gaoxiong.aliyuncs.com

settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
      <mirror>
        <id>aliyunmaven-central</id>
        <mirrorOf>central</mirrorOf>
        <name>阿里云公共仓库</name>
        <url>https://maven.aliyun.com/repository/central</url>
      </mirror>
      <mirror>
        <id>repo1</id>
        <mirrorOf>central</mirrorOf>
        <name>central repo</name>
        <url>http://repo1.maven.org/maven2/</url>
      </mirror>
      <mirror>
        <id>aliyunmaven-apache</id>
        <mirrorOf>apache snapshots</mirrorOf>
        <name>阿里云阿帕奇仓库</name>
        <url>https://maven.aliyun.com/repository/apache-snapshots</url>
      </mirror>
    </mirrors>

</settings>

pom

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xiinnn</groupId>
    <artifactId>CTF-Java-Gadget</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- javassist用于更方便构造类 -->
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.27.0-GA</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.14.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.3.24</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <dependency>
            <groupId>rome</groupId>
            <artifactId>rome</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.80</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.24</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
        </dependency>

        <!-- JTAReadObject2JNDI -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.5.0</version>
                <configuration>
                    <mainClass>com.xiinnn.commonly.POJOJackson</mainClass>
                    <classpathScope>compile</classpathScope>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
                        <additionalClasspathElement>${project.build.outputDirectory}</additionalClasspathElement>
                    </additionalClasspathElements>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

改成3.2.2报这个错了

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.xiinnn:CTF-Java-Gadget >---------------------
[INFO] Building CTF-Java-Gadget 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from aliyunmaven-central: https://maven.aliyun.com/repository/central/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.284 s
[INFO] Finished at: 2024-11-19T08:43:13-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project CTF-Java-Gadget: Could not collect dependencies for project com.xiinnn:CTF-Java-Gadget:jar:1.0-SNAPSHOT
[ERROR] Failed to read artifact descriptor for commons-collections:commons-collections:jar:3.2.2
[ERROR]     Caused by: The following artifacts could not be resolved: commons-collections:commons-collections:pom:3.2.2 (absent): Could not transfer artifact commons-collections:commons-collections:pom:3.2.2 from/to aliyunmaven-central (https://maven.aliyun.com/repository/central): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

原项目用默认用的3.2.1。不应该报错的

4.4的报错

└─$ mvn install
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.xiinnn:CTF-Java-Gadget >---------------------
[INFO] Building CTF-Java-Gadget 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from aliyunmaven-central: https://maven.aliyun.com/repository/central/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.pom
Downloading from aliyunmaven-central: https://maven.aliyun.com/repository/central/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.035 s
[INFO] Finished at: 2024-11-19T10:17:12-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project CTF-Java-Gadget: Could not collect dependencies for project com.xiinnn:CTF-Java-Gadget:jar:1.0-SNAPSHOT
[ERROR] Failed to read artifact descriptor for org.apache.commons:commons-collections4:jar:4.4
[ERROR]     Caused by: The following artifacts could not be resolved: org.apache.commons:commons-collections4:pom:4.4 (absent): Could not transfer artifact org.apache.commons:commons-collections4:pom:4.4 from/to aliyunmaven-central (https://maven.aliyun.com/repository/central): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[ERROR] Failed to read artifact descriptor for commons-collections:commons-collections:jar:3.2.2
[ERROR]     Caused by: The following artifacts could not be resolved: commons-collections:commons-collections:pom:3.2.2 (absent): Could not transfer artifact commons-collections:commons-collections:pom:3.2.2 from/to aliyunmaven-central (https://maven.aliyun.com/repository/central): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException   
阅读 556
avatarAI BotBETA
这个问题是由于 Maven 在尝试从 Aliyun Maven 仓库下载依赖时,无法验证 SSL 证书的有效性导致的。尽管你已经通过 `-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true` 参数尝试忽略 SSL 安全验证,但这通常不是解决问题的最佳方法,因为这些参数可能会使你的构建过程容易受到中间人攻击。

从你提供的 `keytool` 输出来看,JDK 的 `cacerts` 密钥库中已经包含了 Aliyun 的相关证书。然而,问题可能仍然存在,因为:

1. **证书路径问题**:可能你的 JDK 环境中的证书路径没有正确配置,或者证书链不完整。
2. **Maven 配置问题**:Maven 的配置可能覆盖了 JDK 的默认 SSL 设置。

### 解决方案

1. **确保 JDK 版本和 Maven 版本兼容**:
   确保你使用的 JDK 版本和 Maven 版本是兼容的,并且都是最新的稳定版本。

2. **检查 Maven 的 `settings.xml`**:
   检查你的 Maven `settings.xml` 文件(通常位于 `${M2_HOME}/conf/settings.xml` 或 `${user.home}/.m2/settings.xml`),确保没有配置错误的仓库地址或代理设置。

3. **更新 JDK 的证书库**:
   尽管你的证书库中已经包含了 Aliyun 的证书,但可以尝试更新或重新导入证书,确保证书链是完整的。

4. **使用正确的仓库地址**:
   确保你的 `pom.xml` 文件中配置的 Aliyun 仓库地址是正确的。例如:

<repositories>

   <repository>
       <id>aliyunmaven</id>
       <url>https://maven.aliyun.com/repository/central</url>
   </repository>

</repositories>


5. **不使用不安全的 SSL 参数**:
避免使用 `-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true`,因为这些参数会使 Maven 忽略 SSL 错误,从而增加安全风险。

6. **调试和日志**:
使用 Maven 的 `-X` 参数来启用详细的调试日志,这可能会提供更多关于问题的信息。

7. **考虑网络问题**:
如果你的网络环境有特殊的代理或防火墙设置,确保这些设置不会阻止 Maven 访问 Aliyun Maven 仓库。

如果上述步骤都不能解决问题,你可能需要更深入地检查你的网络配置或联系 Aliyun 支持以获取更多帮助。
2 个回答

你的settings.xml都是错的,我就是纯Linux环境开发,没有任何问题,mirror标签的id怎么能重复呢

参考阿里云云效配置,配置越简单越好

你的 <mirrors> 部分中有两个 <mirror> 使用了相同的 <id> (aliyunmaven)
我给我的配置文件给你看一下
settings.xml

<mirrors>
  <mirror>
    <id>aliyunmaven-central</id>
    <mirrorOf>central</mirrorOf>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/central</url>
  </mirror>
  <mirror>
    <id>repo1</id>
    <mirrorOf>central</mirrorOf>
    <name>central repo</name>
    <url>http://repo1.maven.org/maven2/</url>
  </mirror>
  <mirror>
    <id>aliyunmaven-apache</id>
    <mirrorOf>apache snapshots</mirrorOf>
    <name>阿里云阿帕奇仓库</name>
    <url>https://maven.aliyun.com/repository/apache-snapshots</url>
  </mirror>
</mirrors>

主要修改点

1.唯一的 <id>:每个 <mirror> 现在有唯一的 <id>。
2.激活配置文件:添加了 <activeProfiles> 部分来激活默认配置文件

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏