Slackbot
01/10/2024, 1:41 AMthadhouse
01/10/2024, 2:04 AMclass 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.attributes(attributeContainer -> {
attributeContainer.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "platform-metadata"));
});
});
view.files.each {
println it
}
}
}
Minimal reproducing examplethadhouse
01/10/2024, 7:41 AMVampire
01/10/2024, 7:55 AMthadhouse
01/10/2024, 7:56 AMthadhouse
01/10/2024, 7:58 AMJendrik Johannes
01/10/2024, 11:14 AMartifactView , by default, only operates on the variants that were selected before. It the uses attributes to decide for an artifact (format/type) (NOT to decide for a Variant). This is for triggering artifact transforms.
There is a new feature in artifact views since a few versions: withVariantReselection
If you turn that on for your view, I think you can also use the view to select different variants. But I have never actively used that and do not know how the details work there.
But maybe you do not need this at all. See my answer in the other thread.Vampire
01/10/2024, 11:27 AMwithVariantReselection in the upper example. Shouldn't it then work?thadhouse
01/11/2024, 2:57 AMVampire
01/11/2024, 7:57 AMthadhouse
01/11/2024, 8:03 AMJendrik Johannes
01/11/2024, 8:51 AMVampire
01/11/2024, 9:56 AM