Gradle Bintray插件执行bintrayUpload任务时出现Cannot cast _Decorated错误
Cannot cast _Decorated Error in Gradle Bintray Upload Hey there! Let's break down that frustrating Cannot cast _Decorated error you're facing when running the bintrayUpload task. This issue almost always ties back to configuration mismatches or compatibility problems with the old Gradle Bintray plugin, especially in multi-module projects. Here are the most likely culprits and fixes:
1. Incompatible Gradle & Bintray Plugin Versions
The original com.jfrog.bintray plugin is no longer maintained, and it doesn't play nicely with newer Gradle versions (6.x and above). That type cast error often pops up when the plugin can't handle the decorated objects Gradle uses in newer releases.
- Fix:
- If you're stuck on the old plugin, use the last stable version (
1.8.5) and ensure your Gradle version is 6.x or lower. - For long-term stability, migrate to using the
maven-publishplugin alongside Bintray's REST API (since the old plugin is deprecated).
- If you're stuck on the old plugin, use the last stable version (
2. Mismatched Publication Configuration in Submodules
This is the most common cause in multi-module setups. The error happens when the Bintray plugin can't properly resolve the MavenPublication you've defined, usually because of a naming mismatch or missing plugin application.
Double-check your submodule's Gradle config for these issues:
- Ensure you've applied both the
maven-publishand Bintray plugins (if using the old one):plugins { id 'java-library' id 'maven-publish' id 'com.jfrog.bintray' version '1.8.5' } - Make sure the
publicationsname in yourbintrayblock exactly matches the name of yourMavenPublication:publishing { publications { mavenJava(MavenPublication) { // This name is "mavenJava" from components.java groupId = 'com.your.group' artifactId = project.name version = project.version } } } bintray { user = System.getenv('BINTRAY_USER') key = System.getenv('BINTRAY_KEY') publications = ['mavenJava'] // Must match the publication name above pkg { repo = 'your-bintray-repo' name = 'your-package-name' version { name = project.version } } } - Avoid referencing undefined components or publications—if you skip
from components.java, the plugin won't have a valid artifact to upload, leading to type cast failures.
3. Conflicting Plugin Application Across Root/Submodules
Don't apply the Bintray plugin in both the root project and submodules unless you explicitly configure each submodule's publication independently. Overlapping configurations can cause the plugin to resolve decorated objects incorrectly.
- Fix: Apply the Bintray plugin only in submodules that need to be published, or use
subprojectsblocks carefully to avoid overwriting submodule-specific configs.
4. Migrate to a Deprecation-Proof Workflow (Recommended)
Since the old Bintray plugin is retired, the best long-term fix is to use maven-publish to generate your artifacts and POM files, then upload them directly via Bintray's API. Here's a quick example of a custom upload task:
task uploadJarToBintray(type: Exec) { dependsOn build def jarFile = file("${buildDir}/libs/${project.name}-${project.version}.jar") commandLine 'curl', '-X', 'PUT', '-u', "${System.getenv('BINTRAY_USER')}:${System.getenv('BINTRAY_KEY')}", "https://api.bintray.com/content/your-username/your-repo/your-package/${project.version}/${jarFile.name}", '--upload-file', jarFile.path } task uploadPomToBintray(type: Exec) { dependsOn publishToMavenLocal def pomFile = file("${buildDir}/publications/mavenJava/pom-default.xml") commandLine 'curl', '-X', 'PUT', '-u', "${System.getenv('BINTRAY_USER')}:${System.getenv('BINTRAY_KEY')}", "https://api.bintray.com/content/your-username/your-repo/your-package/${project.version}/${project.name}-${project.version}.pom", '--upload-file', pomFile.path } task uploadToBintray(dependsOn: [uploadJarToBintray, uploadPomToBintray])
Start with verifying your plugin versions and publication name matches—those are the quickest fixes. If you still hit issues, share a snippet of your full submodule Gradle config, and we can narrow it down further!
内容的提问来源于stack exchange,提问作者Mad Scientist Moses

