MacOS安装Fast-DDS-Gen遇Gradle错误:无法设置classifier属性
问题:MacOS安装Fast-DDS-Gen时执行
gradle assemble失败 背景
在MacOS 12.3.1系统上安装Fast-DDS-Gen,执行以下步骤:
- 通过
brew install gradle安装Gradle - 克隆仓库并构建:
cd ~ git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git cd Fast-DDS-Gen gradle assemble
错误信息
执行gradle assemble时出现如下错误:
> Task :buildIDLParser FAILED FAILURE: Build failed with an exception. * Where: Build file '/Users/scott/Fast-DDS-Gen/thirdparty/idl-parser/build.gradle' line: 79 * What went wrong: A problem occurred evaluating project ':idl-parser'. > Could not set unknown property 'classifier' for task ':idl-parser:sourceJar' of type org.gradle.api.tasks.bundling.Jar. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 1s 2 actionable tasks: 2 executed
当前Gradle环境
------------------------------------------------------------ Gradle 8.0.2 ------------------------------------------------------------ Build time: 2023-03-03 16:41:37 UTC Revision: 7d6581558e226a580d91d399f7dfb9e3095c2b1d Kotlin: 1.8.10 Groovy: 3.0.13 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 19.0.2 (Homebrew 19.0.2) OS: Mac OS X 12.3.1 x86_64
解决方案
方案1:修改构建脚本适配Gradle 8.x
错误原因是Gradle 8.x中,Jar任务的classifier属性已被移除,替换为archiveClassifier。需要修改thirdparty/idl-parser/build.gradle文件的第79行:
- 原代码:
classifier = 'sources' - 修改为:
archiveClassifier = 'sources'
修改后重新执行gradle assemble即可完成构建。
方案2:降级Gradle到兼容版本
Fast-DDS-Gen当前版本可能未适配Gradle 8.x,可以安装Gradle 7.x版本:
- 卸载当前Gradle:
brew uninstall gradle - 安装指定版本(比如7.6.3):
brew install gradle@7 - 配置环境变量(如果需要):
echo 'export PATH="/usr/local/opt/gradle@7/bin:$PATH"' >> ~/.zshrc(若使用bash则替换为~/.bash_profile) - 重启终端,执行
gradle -v确认版本为7.x后,重新运行gradle assemble
内容的提问来源于stack exchange,提问作者leo0807
相关产品推荐
相关产品推荐

