Configuration.copyRecursive() and test-fixtures I...
# plugin-development
a
Configuration.copyRecursive() and test-fixtures I'm trying to create a recursive copy of
testRuntimeClasspath
, resolve it and iterate through the resolved artifacts. But if there are test fixtures, it fails with
Copy code
> Could not resolve all artifacts for configuration ':app:testRuntimeClasspathCopy'.
   > Could not resolve project :app.
     Required by:
         project :app
      > Unable to find a variant with the requested capability: feature 'test-fixtures':
           - Variant 'testRuntimeClasspathCopy' provides 'playground:app:unspecified'
It looks like something is missing from the copy of the original configuration. Is this expected? Thanks! I have a little playground project to reproduce the issue here https://github.com/aloubyansky/playground/tree/gradle-copyRecursive-test-fixtures Commenting out https://github.com/aloubyansky/playground/blob/gradle-copyRecursive-test-fixtures/plugin/src/main/java/org/example/GreetingTask.java#L21 works. (I realize referencing a
Project
from a task is a bad practice, this is just a reproducer).
o
It's generally recommended to avoid `copy`/`copyRecursive` if possible, as they can have strange behavior and are usually not necessary, due to
extendsFrom
. Why do you need to use it here?
a
It's a bit complicated. I need to perform some analysis of the dependencies of the original configuration, based on which I may need to add component variants for some dependencies and possibly perform a few iterations of that. Perhaps i could do my own copying instead but i might run into the same issues?
o
It may have better behavior if you do and also copy the superconfigurations (
getExtendsFrom()
), as it won't be merging dependencies from all superconfigurations.
a
interesting, thanks, i'll try that
o
Removing the
copyRecursive()
and creating a new configuration with
configurations.resolvable
and
conf.setExtendsFrom(project.getConfigurations().getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME).getExtendsFrom());
results in what looks like expected behavior:
Copy code
> Task :app:greeting
- app-test-fixtures.jar (project :app)
- app.jar (project :app)
- xom-1.3.9.jar (xom:xom:1.3.9)
- xercesImpl-2.12.2.jar (xerces:xercesImpl:2.12.2)
- xml-apis-1.4.01.jar (xml-apis:xml-apis:1.4.01)
However, you might need to also copy the attributes to get fully correct resolution.
🙏 1
a
why are you not using simply
conf.setExtendsFrom(project.getConfigurations().getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME))
?
o
I'm not confident that extending from a resolvable configuration is the right thing to do here, or even something that should be done in general, and as it can't have dependencies declared on it anyways it's not necessary.
a
just in case, i tried
Copy code
baseConfig.getAllDependencies().forEach(dependency -> {
            config.getDependencies().add(dependency);
        });
but it resulted in the same error as
copyRecursive
, so it seems like
extendsFrom
is the way to go
and i suppose i won't need to copy the exclude rules with
extendsFrom
v
Drawback of getting extends from and setting it is, that it is rather, so if the extends from changes later you do not see that, while you would get it if you extended the resolvable configuration directly.
Regarding proper copying if you need a copy, you should have a look at Ben Manes versions plugin. It does the copying, because it also changes the dependency versions to find the latest version, so extending would probably not work there
🙏 1
a
yeah, in my actual project i think i have to just extend from the base configuration, instead of getting its
extendsFrom