POMs on the classpath [SOLVED]

I have a problem with Gradle adding POMs to the classpath, and it’s causing some tests in some legacy code (which uses an extremely flakey classpath scanning library) to fail.

I couldn’t find anybody else having the same problem as me, so I tried this workaround:

test {
    sourceSets.test.compileClasspath = sourceSets.test.compileClasspath.filter {
        ! it.name.endsWith(".pom")

    sourceSets.test.compileClasspath.each {
        logger.warn "[!!] ${it}"

I do not see any log messages with any POM dependencies when I run this, but the test still fails (and a breakpoint before the test tells me that the POMs have re-appeared in java.class.path.

I have also tried moving the workaround into a test { doFirst { //… } } but the result is the same.

Can anybody shed any light on

  1. Why Gradle is appending the POMs to the classpath? Yes I have POM-only dependencies but Gradle knows what POMs are for and that they shouldn’t be involved at runtime

  2. Why manually taking these things out of the classpath doesn’t seem to stick?

Many thanks in advance.

We’ve had this problem and done something similar to you. Do you by any chance have both Maven and Ivy repositories configured in the build?

No there’s no Ivy involved at all. Did you find any other solutions or workarounds? Like I said changing the test.compileClasspath by hand seems to get lost at runtime and we’re back to square one

I never heard of a similar problem before. Can you share your dependency block? or even better a small reproducable example that demonstrates the problem of having pom files on the classpath?

The actual problem isn’t caused by Gradle, it’s caused by an in-house library (which can’t be changed). It loops through every entry on the classpath and examines the contents of the JAR. The POMs /should/ be ignored but instead it throws an exception - that’s why I thought manually taking them out of the classpath should be good enough

The problem also shows up if Findbugs is run on a classpath that contains POM, but no JARs.

this manipulates the compile classpath of the sourceset, but not of the classpath of the test task. try this

test.classpath = sourceSets.test.runtimeClasspath.filter { 

That’s got it working, thank you very much. Should have noticed I was changing the compile classpath, really.

Thanks again.