This message was deleted.
# community-support
s
This message was deleted.
j
Copy code
target.afterEvaluate {
    val implementationDependencies =
        target.configurations["implementation"]
            .allDependencies
            .filterIsInstance<DefaultProjectDependency>()
            .toSet()
    target.dependencies {
        for (dep in implementationDependencies) {
            "contextual"(target.project(dep.dependencyProject.path))
        }
    }
}
I don't like the
afterEvaluate
I am unable to know if my plugin is being applied in the other dependency too, so I would like to add it in a safer way automatically. I think for knowing the plugin part it can be only done in a settings plugin, right?
c
Have your configuration extend from implementation.
👆 2
thank you 1
j
I am getting this issue
Copy code
- Incompatible because this component declares a component, packaged as a jar and the consumer needed a component, with the library elements 'contextual'
the library which is reporting the issue is another one which is not a project and which doesn't have the
contextual
part, so it looks like this issue is "similar" to an android library which has two variants and other which has three and it doens't know what to pick, and you need fallbacks and so on. cc @Thomas Broyer
how can somehow filter this?
https://docs.gradle.org/current/userguide/declaring_dependencies.htmlhttps://docs.gradle.org/current/userguide/feature_variants.htmlhttps://docs.gradle.org/current/userguide/variant_model.html I have read that and I ended up on this too https://github.com/gradle/gradle/issues/12126 TBH, I "understand" what is the problem and it is expected, but I don't understand how to do optional attributes or variants. My
contextual
is extending
implementation
, and one of the dependencies added to
implementation
doesn't know anything about
contextual
which is normal, because that dependency hasn't be processed by my plugin, but, that means that dependency has not added any artifact to the
contextual
as there is no
contextual
, so it must be skipped. How can I mark this attribute as optional?
v
Attributes are optional by default
But you did not invent a new attribute, you added a value to an existing one
So having it optional is not helping
You can declare a compatibility rule, so that you can get
whatever
if
contextual
was requested, but then you get the
whatever
jar.
If you not want the dependency if
contextual
is not present, use a lenient artifact view.
a
This stuff is really hard and difficult to figure out. You can try using an artifact view with variant reselection
Copy code
val contextual by configurations.creating { ... }

contextual.incoming.artifactView {
  withVariantReselection()
  //lenient(true) // you can also try ignoring failures
}.files
sometimes I found that ‘resolved artifacts’ was necessary - something to do with triggering transforming files
Copy code
val contextual by configurations.creating { ... }

val contextualContents: Provider<List<File>> = contextual.incoming
  .artifactView {
    //lenient(true) // you can also try ignoring failures
    withVariantReselection()
  }.artifacts
  .resolvedArtifacts
  .map { artifacts ->
    artifacts.map { it.file }
  }
j
interesting, I think
lenient
is what I was calling "optional" attribute, thank you both, I will try 🙂
👍 1
lenient(true)
works, if I only use
withVariantReselection()
it doesn't work.
thank you 😛
v
if I only use
withVariantReselection()
it doesn't work
Of course not, why should it? That method means "ignore the attributes declared on the configuration and just resolve again with only the artifact view defined attributes". That doesn't change that your dependency has no matching variant.
j
Thank you for the clarification! TBH it is hard to understand the whole variants concept
v
Yes, I also needed quite some time to wrap my head around it and am still not 100% sure I fully got it. 😄 But once you got the grasp it is not that hard anymore. 🙂
😄 1