简体   繁体   中英

Avoid dependency/classpath conflict between Gradle plugins

I'm using two gradle plugins in a project :

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'pluginA:1'
        classpath 'pluginB:1'
    }
}

apply plugin: 'pluginA'
apply plugin: 'pluginB'

Both pluginA and pluginB relies on xerces but in uncompatible versions... The problem is that execution of pluginA fails because the wrong version of xerces is used.

Is it possible to separate the classpath used for each plugin task execution (each plugin having only its own classpath during the execution of one of its task) ?

You might be able to use something like the ClassLoadersPlugin from here to create different classloaders for your tasks based on different configurations, and then specify your dependencies against those configurations. Not sure if this extends to a plugin scenario though, but it might, as the plugins are just creating tasks presumably, the eventual running of them would use different classloaders.

Alternatively the apply method takes a map , and you can specify what the objects it is applying to, so that not everything is done on the same project object.

Edit: Another avenue might be to look at excluding the dependency as detailed in Excluding transitive dependencies and creating configurations that specifically include the two xerces libs, and basing your tasks to run off those configurations, which would seem more "OOTB".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM