使用JReleaser发布Java库报错:stagingRepository不存在
JReleaser Gradle Kotlin DSL配置报错与参数咨询
我的JReleaser Gradle Kotlin DSL配置
jreleaser { gitRootSearch = true signing { active.set(Active.ALWAYS) armored.set(true) } deploy { maven { nexus2 { create("mavenCentral") { active.set(Active.ALWAYS) url.set("https://s01.oss.sonatype.org/service/local") snapshotUrl.set("https://s01.oss.sonatype.org/content/repositories/snapshots/") closeRepository.set(true) releaseRepository.set(true) stagingRepository("target/staging-deploy") } } } } }
执行任务时的报错信息
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':lib:jreleaserFullRelease'. > maven.nexus2.mavenCentral.stagingRepository does not exist: target/staging-deploy
问题说明
执行:lib:jreleaserFullRelease任务时失败,报错提示指定的stagingRepository目录不存在。由于Gradle Kotlin DSL相关教程较少,想请教stagingRepository参数的具体含义,若需要补充publishing部分的配置可以提供。
解答
stagingRepository参数含义
stagingRepository是JReleaser对接Nexus 2发布时的本地临时中转目录:
- 它的作用是先把所有待发布的构建产物(比如jar包、pom文件、签名文件等)统一存放到这个本地目录,再一次性上传到远程的Nexus Staging仓库。
- 相当于本地与远程仓库之间的缓冲层,确保所有文件准备齐全后再发起远程上传,避免因部分文件缺失导致发布失败。
报错原因及解决方法
报错核心原因是你配置的target/staging-deploy目录不存在,或者当前Gradle进程没有权限创建该目录。解决办法有两种:
- 手动创建目录:在
lib模块目录下,手动新建target/staging-deploy文件夹 - 改用Gradle自动管理的目录:将参数改为
build/staging-deploy,这个目录属于Gradle默认的构建输出目录,执行任务时Gradle会自动创建,无需手动操作
如果你的项目配置了publishing插件,只需确保其产物输出路径与JReleaser配置兼容即可,但当前问题的核心是保证stagingRepository指定的本地目录存在且可读写。
内容的提问来源于stack exchange,提问作者Luís Soares
相关产品推荐
相关产品推荐

