Skip to content

compileOnlyTest.extendsFrom { compileOnly } is performed too lazily #114

@jjohannes

Description

@jjohannes

It's done during task configuration for it to be done "late". The reason for that decision was that users may re-configure a test suite between the different modes – WHITEBOX, CLASSPATH, BLACKBOX. And this should only be done for WHITEBOX, which is the default for test sets without module-info.

However, doing it like this may cause the following warning:

Mutating  a configuration after it has been resolved, consumed as a variant, or used for generating published metadata. This behavior has been deprecated. 
  This will fail with an error in Gradle 9.0.
  After a configuration has been observed, it should not be modified.

https://scans.gradle.com/s/ebi3zstoepr22/deprecations?expanded=WyI0Il0

Workaround is to explicitly define the extendsFrom in the build. Then the plugin won't do it again:

configurations.compileOnlyTest { extendsFrom(configurations.compileOnly.get()) }

I think the best solution it to add the extendsFrom directly and remove it again on test suite re-configuration.
Code to be adjusted:

Configuration compileOnly = configurations.getByName(sourcesUnderTest.getCompileOnlyConfigurationName());
Configuration testCompileOnly = configurations.getByName(testSources.getCompileOnlyConfigurationName());
if (!testCompileOnly.getExtendsFrom().contains(compileOnly)) {
testCompileOnly.extendsFrom(compileOnly);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions