You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle构建的Jar包发布至Nexus遇SSL错误求助

解决Gradle发布Nexus时的"Unsupported or unrecognized SSL message"错误

针对你遇到的发布失败问题,这个错误核心是客户端尝试发起SSL握手,但收到了非SSL响应,下面是几个针对性解决步骤:

1. 优先检查Nexus仓库的协议是否正确

很多Nexus实例默认配置的是HTTP服务而非HTTPS。你当前用了https://开头的地址,可以先尝试把协议改成http,再重新执行发布任务:

url "http://54.89.194.112:8081/repository/maven-snapshots/"

2. 若确认使用HTTPS,处理证书信任问题

如果Nexus确实启用了HTTPS,错误可能是JVM不信任Nexus的SSL证书,可按以下步骤导入证书:

  • 先下载Nexus的证书:
    openssl s_client -connect 54.89.194.112:8081 < /dev/null | openssl x509 -outform PEM > nexus.crt
    
  • 将证书导入JVM系统信任库(替换为你的JDK安装路径):
    keytool -importcert -file nexus.crt -keystore /path/to/your/jdk/jre/lib/security/cacerts -alias nexus-cert
    
    系统信任库默认密码为changeit

3. 调整Gradle的SSL配置

可以在发布仓库配置中明确指定SSL参数,或临时禁用证书验证(仅用于测试环境,生产环境禁止):

maven {
    name 'nexus'
    url "https://54.89.194.112:8081/repository/maven-snapshots/"
    credentials {
        username project.repoUser
        password project.repoPassword
    }
    ssl {
        // 自定义信任库路径(若导入证书到自定义库)
        trustStore = file("/path/to/custom/truststore.jks")
        trustStorePassword = "your-truststore-password"
        // 测试环境临时禁用证书校验(不推荐生产)
        // insecure = true
    }
}

4. 确保JDK的SSL协议配置生效

你在脚本中设置System.setProperty("https.protocols", "TLSv1.2")可能时机不对,建议通过Gradle启动参数配置:
在项目根目录的gradle.properties中添加:

org.gradle.jvmargs=-Dhttps.protocols=TLSv1.2

内容的提问来源于stack exchange,提问作者Akash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 19:08:26