Jitpack构建app模块而非library模块导致部署失败求助
Jitpack部署库构建错误排查与解决
问题现象
构建日志报错:
Gradle 'publishToMavenLocal' task not found. Please add the 'maven-publish' or 'maven' plugin.
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
FAILURE: Build failed with an exception.
- Where:
Build file '/home/jitpack/build/app/build.gradle' line: 52
最终报错:
⚠️ ERROR: No build artifacts found
推测Jitpack正在构建app模块而非目标library模块,已配置jitpack.yml:
jdk: - openjdk11 project: library_folder_name
但问题未解决。
补充信息:
- 本地执行
publishToMavenLocal正常; - artifact_id与仓库名称一致;
- group_id符合
com.github.<MY_GIT_USER_NAME>格式。
解决步骤
1. 确认library模块的Gradle配置
确保library模块的build.gradle(或build.gradle.kts)中已添加maven-publish插件,并正确配置发布任务:
plugins { id 'com.android.library' id 'maven-publish' // 必须添加 } // 配置发布内容示例 afterEvaluate { publishing { publications { release(MavenPublication) { from components.release groupId = 'com.github.你的用户名' artifactId = '仓库名' version = '1.0.0' } } } }
2. 修正jitpack.yml配置
如果library模块在项目子目录,确保project路径准确,比如模块在./library目录下,配置应为:
jdk: - openjdk11 project: library
可添加明确的构建任务指定,避免Jitpack默认构建app模块:
jdk: - openjdk11 project: library_folder_name tasks: - publishToMavenLocal
3. 检查项目根目录settings.gradle
确保library模块已被正确包含:
include ':library_folder_name' // 若模块在深层子目录,需指定路径 // include ':library' // project(':library').projectDir = file('./path/to/library')
4. 排除app模块干扰
在app模块的build.gradle中添加条件判断,避免Jitpack构建app:
// app模块build.gradle if (!project.hasProperty('jitpack')) { apply plugin: 'com.android.application' // ... 其他app专属配置 }
5. 验证构建路径与缓存
- 确认
jitpack.yml已提交到仓库根目录; - 触发Jitpack重新构建,查看日志是否切换到library模块路径;
- 若路径仍错误,清理Jitpack缓存后重试。
内容的提问来源于stack exchange,提问作者Samuel Agbesinyale
相关产品推荐
相关产品推荐

