Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 739
Chris Kessel Avatar asked Apr 22 '15 19:04

Chris Kessel


2 Answers

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'     } } 
like image 151
Chris Kessel Avatar answered Sep 20 '22 06:09

Chris Kessel


Here's another potential cause. All of this looks to be a problem with rival classloaders defining the class. The full qualified classes include the loader. so, load A foo.bar is not loader B foo.bar and crossing that divide is a complex dance requiring interfaces and careful definition.

So, when using the Jenkins artifactory plugin to build your gradle project with the gradle artifactory plugin, you must add the usesPlugin or jenkins plugin will generate an init script which adds the gradle plugin on to a class loader.

def server = Artifactory.server "artifactory" def rtGradle = Artifactory.newGradleBuild() rtGradle.usesPlugin = true // Artifactory plugin already defined in build script ... 

My problem was, desktop build OK, jenkins build shows this post's problem

like image 43
Peter Kahn Avatar answered Sep 20 '22 06:09

Peter Kahn