Removing lib/plugins jars from a projects classpath

I am experiencing a similar issue to the following:

Summarized issue:

When developing a gradle plugin, and thereby having a dependency on gradleApi(), jars from 3rd party plugins in the lib/plugins directory are added as dependencies on my project. Based on their ordering in the classpath, these jars create version conflicts with jars I am actually trying to use as dependencies.

Is there a way to exclude these unwanted jars being pulled in from lib/plugins?

I believe you’re running into the same problem that I hit a while ago. Some code that my plugin uses required commons-io version 2.4, but Gradle at the time internally used version 1.4, and it would get that version first. The only way I know of to deal with this is to specifically remove the older jar from both the compile and runtime classpath variables, like this (I added the “integTest” sourceset for integration tests):

sourceSets {
    main {
        compileClasspath = configurations.compile.minus files("$gradle.gradleHomeDir/lib/commons-io-1.4.jar")
    integTest {common
        runtimeClasspath = output + compileClasspath - files("$gradle.gradleHomeDir/lib/commons-io-1.4.jar")