This message was deleted.
# community-support
s
This message was deleted.
t
Copy code
class DirectMetadataAccessVariantRule implements ComponentMetadataRule {
    @javax.inject.Inject
    ObjectFactory getObjects() { }
    void execute(ComponentMetadataContext context) {
        def id = context.details.id
        context.details.addVariant("moduleMetadata") {
            attributes {
                attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
                attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.REGULAR_PLATFORM))
                attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "platform-metadata"))
            }
            withFiles {
                removeAllFiles()
                addFile("${id.name}-${id.version}.module")
            }
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    components {
        all(DirectMetadataAccessVariantRule)
    }
}

task runThing {
    doLast {
        def dep = project.dependencies.create('org.junit:junit-bom:5.10.1')
        def detached = project.configurations.detachedConfiguration(dep)

        def view = detached.getIncoming().artifactView(viewConfiguration -> {
            viewConfiguration.withVariantReselection()
            viewConfiguration.lenient = true
            viewConfiguration.attributes(attributeContainer -> {
                attributeContainer.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "platform-metadata"));
            });
        });
        // Actually fails here
        view.files.each {
            println it
        }

        view = detached.getIncoming().artifactView(viewConfiguration -> {
            viewConfiguration.withVariantReselection()
            viewConfiguration.attributes(attributeContainer -> {
                attributeContainer.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "platform-metadata"));
            });
        });
        // Would expect failure here
        view.files.each {
            println it
        }
    }
}
Reproducing example. I would expect the failure to happen at line marked would expect failure here, but it actually occurs at actually fails here
v
As you can see at https://github.com/gradle/gradle/blob/master/platforms%2Fjvm%2Fjacoco%2Fsrc%2Fmain%2Fjava%2Forg%2Fgradle%2Ftesting%2Fjacoco%2Fplugins%2FJacocoReportAggregationPlugin.java#L88-L107, it is expected that you can have multiple artifact views on the same configuration, so yes, it should work properly. If it does not, you should report an error.