Hi!
Am I using the maven-publish
plugin to publish some artifact (in this case a version catalog).
Now I want to add an artifact (with metadata) to the publication. This artifact is produced by a subproject.
I have declared an outgoing configuration that contains the artifact:
producer/build.gradle.kts
:
val producerTask by tasks.registering {
val outFile = project.layout.buildDirectory.file("greeting.txt")
outputs.file(outFile)
doLast {
outFile.get().asFile.writeText("hello world!")
}
}
val markerAttribute = Attribute.of("com.example.greeting", String::class.java)
dependencies.attributesSchema {
attribute(markerAttribute)
}
val greetingConfiguration by configurations.creating {
isCanBeResolved = false
isCanBeConsumed = true
outgoing {
artifact(producerTask)
}
attributes {
attribute(markerAttribute, "true")
}
}
Now I want to include this configuration in the publishing of a different module by modifying the published component:
consumer.gradle.kts
:
(components["versionCatalog"] as? AdhocComponentWithVariants)
?.addVariantsFromConfiguration(?????) { }
I have tried to create a configuration with the appropriate attribute and a dependency to project(":producer")
, but then the generated metadata for publishing looks like this:
…
{
"name": "greeting",
"attributes": {
"com.example.greeting": "true"
},
"dependencies": [
{
"group": "myproject",
"module": "producer",
"version": {
"requires": "unspecified"
}
}
]
}
…
However I want it like:
…
{
"name": "greeting",
"attributes": {
"com.example.greeting": "true"
},
"files": [
{
"name": "greeting-0.1-SNAPSHOT.txt",
…
}
]
}
…
Is this possible?