Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classpath is set incorrectly when using tasks.withType(Test) configuration #40

Closed
ketan opened this issue Jan 2, 2018 · 1 comment
Closed

Comments

@ketan
Copy link

ketan commented Jan 2, 2018

I'm applying a classpath to all tests in a multi-project build using tasks.withType. This causes the testClassesDirs to not be on the classpath of the test task configured by the plugin. Here is a test case to reproduce. Save the file as build.gradle and run with gradle clean -q -PadditionalClasspath and then with ./gradlew clean -q. You'll see the following outputs:

As you'll see integrationTest dir is nowhere on the classpath in one of the cases. I'll and work on a fix in the plugin, but in the meanwhile, if there's a workaround — I'd appreciate any pointers :)

$./gradlew clean -q
[/private/tmp/foo/build/classes/java/integrationTest, /private/tmp/foo/build/resources/integrationTest, /private/tmp/foo/build/classes/java/main, /private/tmp/foo/build/resources/main]
$./gradlew clean -q -PadditionalClasspath
[/private/tmp/foo/build/classes/java/test, /private/tmp/foo/build/resources/test, /private/tmp/foo/build/classes/java/main, /private/tmp/foo/build/resources/main, /private/tmp/foo/foo]
plugins {
    id 'org.unbroken-dome.test-sets' version '1.4.2'
}

apply plugin: 'java'

tasks.withType(Test) {
  if (project.hasProperty('additionalClasspath')) {
    classpath += files('foo')
  }
}

testSets {
    integrationTest
}

println integrationTest.classpath.files
@tkrullmann
Copy link
Member

Hi,

I'm afraid this is not a bug - the plugin uses Gradle's convention mapping mechanism to configure the test task. The conventional / default values are not applied once you configure them directly, like classpath in your example.

What you could try is to wrap your additional classpath configuration inside a project.afterEvaluate { } block. That way it should be applied only after the convention mappings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants