Slackbot
02/07/2022, 8:06 AMJendrik Johannes
02/07/2022, 9:22 AMschema.map { project.zipTree(it) }
The map here is not (!!) the Gradle provider map {}. But the normal Kotlin Collections map {}. Because a configuration can be treated as a set of files (Gradle then sneakily resolves the Configuration…) this method is offered here.
This is unfortunately very easy to get wrong. 😞 There is a lot of “legacy” in the Configuration API that would be nice if it could be removed.
When you call this map {}, Gradle looses all task dependency information.
Instead, you can use schema.elements to get a provider for files/folder. On this you can use Gradle’s map{}.
I think something like:
schema.elements.map { zipTree(it) }
could work.Jendrik Johannes
02/07/2022, 9:23 AMproject.artifacts.add("schema-artifact", schemaZip)
Is that used for something?
You already “add the artifact” by
outgoing {
artifact(schemaZip)
}Lars Ködderitzsch
02/07/2022, 10:25 AMschema.elements brought me on the right track, just needed to tweak the from of my copy/unzip task a bit, bc. zipTree didn't like collections of files.
Ended up with this:
val unpackSchemaDependencies by project.tasks.registering(Copy::class) {
group = "build setup"
description = "Extrahiert die Schema-Abhängigkeiten"
from(schema.elements.map {
var fc = project.files()
it.forEach { fc.from(project.zipTree(it)) }
return@map fc
})
into(schemaArtifactSpec._dependenciesDir)
}Lars Ködderitzsch
02/07/2022, 10:28 AMproject.artifacts.add : I need the artifact reference to add it to a maven publication, which in turn is tweaked to reference the potential schema dependencies
val artifact = project.artifacts.add("schema-artifact", schemaZip)
project.configure<PublishingExtension> {
publications {
maybeCreate<MavenPublication>(KONS_PUBLICATION).apply {
artifact(artifact)
pom.withXml {
if (schema.dependencies.isEmpty()) {
return@withXml
}
val depsNode = (asNode().get("dependencies") as NodeList).firstOrNull() as Node?
?: asNode().appendNode("dependencies")
schema.resolvedConfiguration.resolvedArtifacts.distinct().forEach {
depsNode.appendNode("dependency").apply {
appendNode("groupId", it.moduleVersion.id.group)
appendNode("artifactId", it.moduleVersion.id.name)
appendNode("version", it.moduleVersion.id.version)
appendNode("type", it.type)
}
}
}
}
}
}
There is possibly a better way to achieve this, but I haven't figured that out yet 🙂
Thanks againJendrik Johannes
02/07/2022, 10:57 AMproject.components ).
So that the publication is only configured by from(myComponent) . And no direct reference of artifacts or modification of pom files.
Have a look at:
https://docs.gradle.org/current/userguide/publishing_customization.html#sec:publishing-custom-componentsLars Ködderitzsch
02/07/2022, 2:15 PM<type>zip</type>). Explicitly setting the type on the outgoing artifact doesn't seem to do the trick and I found no API to map a type for the Maven dependency (e.g. similar to mapToMavenScope)
val `schema-artifact` by project.configurations.creating {
isTransitive = true
isCanBeConsumed = true
isCanBeResolved = false
extendsFrom(schema)
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, project.objects.named("schema"))
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.EXTERNAL))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named("schema-artifact"))
}
outgoing {
artifact(schemaZip) {
type = Zip.ZIP_EXTENSION
}
}
}
val schemaComponent = softwareComponentFactory.adhoc("schema")
project.components.add(schemaComponent)
schemaComponent.addVariantsFromConfiguration(`schema-artifact`) {
}
project.configure<PublishingExtension> {
publications {
maybeCreate<MavenPublication>(KONS_PUBLICATION).apply {
from(schemaComponent)
}
}
}Lars Ködderitzsch
02/07/2022, 2:44 PMschema configuration get type=zip when writing the POM.Jendrik Johannes
02/07/2022, 3:57 PMJendrik Johannes
02/07/2022, 4:02 PMpom.withXml and iterate though the dependencies there to add the “type” attribute.
There is an issue for that. And I actually wrote about the workaround there…
https://github.com/gradle/gradle/issues/3170#issuecomment-544248344Lars Ködderitzsch
02/08/2022, 5:58 AM