Remove a jar file from testCompile dependency

What is the best syntax to remove a jar file from the testCompile dependency. I have found the follow solution:

dependencies {
    compile ':AbcObfuscated'
    testCompile ':AbcVanilla'
}
compileTestJava {
    classpath = classpath.filter{ File file ->
        !file.name.equals( "Abc.jar" )
    }
}

But is is not nice. I look for some think like the follow:

dependencies {
    compile ':AbcObfuscated'
    testCompile.exclude ':AbcObfuscated'
    testCompile ':AbcVanilla'
}

Or we can change the order of the jar files that testCompile come before compile.

Maven and Ivy dependencies can be excluded with ‘configuration.exclude’. For project/file dependencies, I’m not aware of a better solution than ‘configuration.filter’. And I wouldn’t rely on ordering.

This means my solution is already the best solution?

I would think so. The filter statement can be shortened to ‘classpath = classpath.filter { it.name == “Abc.jar” }’.

Thanks, I have use now: classpath = classpath.filter { it.name != “Abc.jar” }.

Seems that this doesn’t work any more. I am left with the following error message.

  • Where:

Build file ‘/home/yves/arbeit/fidesmo/ykneo-oath/build.gradle’ line: 22

  • What went wrong:

A problem occurred evaluating root project ‘ykneo-oath’.

Could not find property ‘exclude’ on

org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@1a3836f1.

How can I affect the odering of the jars? Are they sorted in the order they are added?

Yes, the order is equals to the adding order.