This message was deleted.
# dependency-management
s
This message was deleted.
v
Why is pointing at a test not helpful? What it shows is, that you can use a component metadata rule to add a variant that has the GMM as artifact. Then you can use a configuration or artifact view to request that variant to get the file
t
I tried kind of following the test, but the view had only the normal artifacts and not the poms or GMM. I'm sure I did something wrong, but the test provides no clue where because they're meant for a specific use case, that isn't what I'm running into.
Copy code
class DirectMetadataAccessVariantRule implements ComponentMetadataRule {
    @javax.inject.Inject
    ObjectFactory getObjects() { }

    void execute(ComponentMetadataContext context) {
        def id = context.details.id
        context.details.maybeAddVariant("apiElementsWithMetadata", "api") {
            attributes {
                attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
                attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "all-files"))
            }
            withFiles {
                addFile("\${id.name}-\${id.version}.pom")
                addFile("\${id.name}-\${id.version}.module")
            }
        }
        context.details.maybeAddVariant("compileWithMetadata", "compile") {
            attributes {
                attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
                attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "all-files"))
            }
            withFiles {
                addFile("\${id.name}-\${id.version}.pom")
            }
        }
    }

}

configurations.nativeRelease {
    attributes { attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "all-files")) }
}
dependencies {
    components {
        all(DirectMetadataAccessVariantRule)
    }
}

task runThing {
    doLast {
        def cfg = project.configurations.nativeRelease
        ArtifactView view = cfg.getIncoming().artifactView(viewConfiguration -> {
            viewConfiguration.attributes(attributeContainer -> {
                attributeContainer.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "all-files"));
            });
        });
        view.files.each {
            println it
        }
        println it
    }
}
That was the code I had, and the files resolved are only the actual artifacts, and not the pom/gradle module files
I figured it out, and it might be a bug in how artifact views work. The dependencies I was passing in had classifiers, and it seems like the view just ignores any variant stuff at that point, and just returns the files.
v
With classifier, you say "I want exactly that classified file". If you would instead have used a component metadata rule to create a variant for that classified file, I would probably have worked. For example like shown at https://docs.gradle.org/current/userguide/component_metadata_rules.html#making_different_flavors_of_a_library_available_through_capabilities