Gradle artifactory plugin saying "Cannot cast object 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention'..."

Chris Kessel picture Chris Kessel · Apr 22, 2015 · Viewed 6.9k times · Source

Here's the configuration to get the artifactory plugin:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://jcenter.bintray.com' }
    }
    dependencies {
        classpath group:'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1'
    }
}
apply plugin:'com.jfrog.artifactory'
apply plugin:'ivy-publish'

...some publish spec stuff...

I run gradle (2.3) and I get:

> Failed to apply plugin [id 'com.jfrog.artifactory']
   > Cannot cast object 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention@6b6c7be4' with class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention' to class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention'

Certainly looks like a classpath issue, but I literally have this project and a sibling project using this same set of gradle/artifactory configurations and one works and the other does not. Both are part of the same top level project. Same JDK (1.8.0_20). Same Gradle. Same everything.

I'm baffled...

Answer

Chris Kessel picture Chris Kessel · Apr 22, 2015

The problem was that when I added the various bits to the sibling project that meant I had two projects defining the buildscript {} section.

buildscript {
    ...
    dependencies {
        classpath group:'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1'
    }
}

Apparently that caused two different versions of the dependency to exist in the classpath, hence the error.

The solution was to move the buildscript bit into the master project so those dependencies are only defined once:

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath group:'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1'
    }
}