Buildscript classpath problems with multi project build

plugins

(JF Bibeau) #1

Hi, I’m running into a really strange classpath problem with gradle multi-project builds…

I have an empty top level project, which only contains a settings.gradle file with my subproject names:

include 'project-A'
include 'project-B'

Each of those projects has a buildscript section with a custom build plugin:

buildscript {
    repositories {
        maven {
            url = "${artifactory_plugin_url}"
        }
    }
    dependencies {
        classpath 'com.test:my-build-plugin:0.1.0'
    }
}

Everything fine so far and it works. However if I introduce a 2nd classpath in one of my subprojects, for example let’s say I add the proguard plugin:

buildscript {
    repositories {
        maven {
            url = "${artifactory_plugin_url}"
        }
    }
    dependencies {
        classpath 'net.sf.proguard:proguard-gradle:5.2.1'
        classpath 'com.test:my-build-plugin:0.1.0'
    }
}

Then I get a ClassCastException from the Artifactory plugin, which I reference from my custom build plugin:

> Cannot cast object 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention@192b4148' with class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention' to class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention'

If I remove the classpath for proguard, everything works again. It’s not specific to proguard, anytime I add a 2nd classpath definition, it breaks with this exception. From a bit of Googling most people seem to get this exception when there are “multiple versions” of a plugin on the classpath…

What could be causing this? Does this sound like something special in the Artifactory gradle plugin, or is this more of a general buildscript gotcha with multi-project builds??

Thanks!


(Marco Ehrentreich) #2

I’m currently experiencing a similar phenomenon with a custom plugin I have written. Under some circumstances I also get such a strange ClassCastException for a (random) class that is part of the plugin project. It also states two times the exact same class name.

I wasn’t yet able to figure out a pattern when this happens or for which class it happens. The plugin is used only for Android modules in a multi-project setup. Everything works fine when the plugin is applied to a simple Android dummy app but it fails when the plugin is applied to the relevant modules of the “real” project. The dummy app is smaller and simpler but I thought it should be comparable enough to the real thing but easier to test the plugin. So I can’t really tell if the plugin just works on accident for the dummy app or in which ways the dummy app is simpler than the real project.

In particular I get this error from a task class which in turn uses other classes from the plugin project. On the other hand a different but also very simple task class works without any problems. Also the plugin class itself which is interacting with some other classes doesn’t seem to be an issue.

So maybe it’s only an issue for task classes although I am not aware of any limitations regarding what you can do or you can not do inside a task action.

Any help would be highly appreciated! Thx!