Gradle项目无法上传Jfrog制品:配置问题求助
Gradle Artifactory发布报错排查:No publisher config found for project
首次搭建Gradle项目,按教程配置build.gradle后执行命令./gradlew artifactoryPublish --stacktrace,出现两个问题:
- 错误提示:
Task :extractModuleInfo No publisher config found for project: test-project - Gradle特性弃用警告,提示构建与Gradle 9.0不兼容
配置文件内容
buildscript { def user = System.getenv("USER") def pass = System.getenv("PASSWORD") def url1 = System.getenv("CONTEXTURL") repositories { maven { url url1 credentials { username = user password = pass } } mavenCentral() } dependencies { classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.28.1" } } plugins { // Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins id 'java-gradle-plugin' // Apply the Groovy plugin to add support for Groovy id 'groovy' } group 'test' version '1.2-SNAPSHOT' apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'maven-publish' apply plugin: 'com.jfrog.artifactory' repositories { mavenCentral() mavenLocal() maven { url System.getenv("URL") } } ext { isSnapshot = version.endsWith("SNAPSHOT") } artifactory { def user = System.getenv("USER") def pass = System.getenv("PASSWORD") def url = System.getenv("CONTEXTURL") contextUrl = url publish { repository { repoKey = isSnapshot ? 'plugins-snapshot-local' : 'plugins-release-local' username = user password = pass } defaults { publications('maven') } } } publishing { publications { mavenJava(MavenPublication) { from components.java } } } dependencies { // Use the awesome Spock testing and specification framework testImplementation libs.spock.core testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } gradlePlugin { // Define the plugin plugins { greeting { id = 'nested.set.domains.greeting' implementationClass = 'nested.set.domains.NestedSetDomainsPlugin' } } } // Add a source set for the functional test suite sourceSets { functionalTest { } } configurations.functionalTestImplementation.extendsFrom(configurations.testImplementation) configurations.functionalTestRuntimeOnly.extendsFrom(configurations.testRuntimeOnly) // Add a task to run the functional tests tasks.register('functionalTest', Test) { testClassesDirs = sourceSets.functionalTest.output.classesDirs classpath = sourceSets.functionalTest.runtimeClasspath useJUnitPlatform() } gradlePlugin.testSourceSets.add(sourceSets.functionalTest) tasks.named('check') { // Run the functional tests as part of `check` dependsOn(tasks.functionalTest) } tasks.named('test') { // Use JUnit Jupiter for unit tests. useJUnitPlatform() }
完整报错信息
./gradlew artifactoryPublish --stacktrace Task :extractModuleInfo No publisher config found for project: test-project Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
问题排查与解决
1. 解决"No publisher config found"错误
- 核心原因:
artifactory配置块中defaults指定的发布ID与publishing块中定义的发布ID不匹配。你在publishing里定义的是mavenJava,但artifactory里写的是publications('maven'),导致插件找不到对应的发布配置。 - 修复步骤:修改
artifactory配置中的defaults部分,把publications('maven')改成publications('mavenJava'),确保ID一致:artifactory { // ... 其他配置不变 publish { // ... 其他配置不变 defaults { publications('mavenJava') } } } - 额外检查:确认环境变量
USER、PASSWORD、CONTEXTURL已正确设置且不为空,避免因环境变量缺失导致配置无效。
2. 处理Gradle特性弃用警告
- 查看具体警告:执行
./gradlew artifactoryPublish --warning-mode all,输出详细的弃用信息,定位具体的问题代码。 - 升级Artifactory插件:当前使用的
build-info-extractor-gradle:4.28.1版本较旧,对Gradle 8.x的兼容性不足,建议升级到最新稳定版(如7.x系列),替换buildscript中的依赖版本:dependencies { classpath "org.jfrog.buildinfo:build-info-extractor-gradle:7.6.0" } - 删除冗余插件应用:
plugins块中已经应用了java-gradle-plugin(包含Java插件功能)和groovy插件,后续重复执行apply plugin: 'java'和apply plugin: 'groovy'属于冗余配置,建议删除这两行,避免冲突。 - 优化测试配置:
sourceSets.functionalTest的配置可以考虑使用Gradle官方推荐的java-test-fixtures插件或更现代的测试套件配置方式,替代手动扩展配置的写法。
内容的提问来源于stack exchange,提问作者arya asda
相关产品推荐
相关产品推荐

