Exclude a transitive file from classpath added by 3rd party plugin

buildship
plugins

(Oleksii Lisikh) #1

I have a nasty problem with Gradle build and transitive resource files.
Let me explain in short.

Plugin X, creates its own configurations and a sourceSet:

// XPlugin.groovy
configurations {
  batman
}
sourceSets {
  batman {
    scala { ... }
    resources { ... }
  }
}

Then it declares the output of main sourceSet as a dependency (!!!):

// XPlugin.groovy
dependencies {
  batman sourceSets.main.output
  batman sourceSets.test.output
}

Both batman and main source sets have logback.groovy in resources folder (which is a problem)
Then I apply this plugin:

// build.gradle
apply plugin: 'some.comapny:x-gradle-plugin:0.0.1'

Result: the logback.groovy from the main source set is taken by logback library in the end.

Is there an option in Gradle to remove the file that is not wanted here, basically the /main/resources/logback.groovy file?

PS I don’t need to build a jar out of batman sourceSet, it’s just a sourceSet runnable via Gradle, e.g.
gradle callBatman
PS tried to handle myself, didn’t succeed, google doesn’t help as well

Thanks for help in advance :slight_smile:


(Oleksii Lisikh) #2

So I managed to handle this problem in an ugly way:
I defined a task to exclude logback.groovy while processingResources task is executed

task excludeLogbackGroovy {
  doFirst {
    processResources.excludes = ['**/logback.groovy']
  }
}

task runBatman(dependsOn: 'excludeLogbackGroovy') {
  ...
}

So now when I do gradle runBatman, the task excludeLogbackGroovy is invoked first that additionally configures the processResources task.

Maybe any better ideas?