Matija Sokol
12/04/2024, 9:42 AMimport org.jetbrains.kotlin.gradle.plugin.attributes.KlibPackaging
val resolvableConfiguration = configurations.resolvable("resolvable") {
attributes.attribute(KlibPackaging.ATTRIBUTE, project.objects.named(KlibPackaging.PACKED))
}
But, if I run this my issue is still here. Exactly, problem is this. For reference, I'm working on KMP project.
So, my questions are:
• Is this code snippet only change I need to do or I need to apply resolvableConfiguration
somewhere?
• In which gradle file I need to do it (project
or module
level)?tapchicoma
12/04/2024, 10:03 AMMatija Sokol
12/04/2024, 10:08 AMPacked
, I also get mentioned errortapchicoma
12/04/2024, 10:11 AMtapchicoma
12/04/2024, 10:13 AMmbonnin
12/04/2024, 10:17 AMartifactType
attribute. How did you choose between reusing the artifactType
vs creating a new one?mbonnin
12/04/2024, 10:18 AMartifactType
describes the "file format" of the artifact.mbonnin
12/04/2024, 10:18 AMMatija Sokol
12/04/2024, 10:29 AMAnton Lakotka [JB]
12/04/2024, 11:33 AMI'm curious if there's some documentation about Gradlethere are not much. But artifactType is a special attribute that used in two places: • secondary variants ◦ so one can include some artifact to outgoing variant as a secondary variant and via setting You can do it like this:attribute.artifactType
val someAttribute = Attribute.of("some.attribute", String::class.java)
val consumableConfiguration = configurations.create("consumable") {
isCanBeConsumed = true
isCanBeResolved = false
attributes {
attribute(someAttribute, "someValue")
}
}
consumableConfiguration.outgoing.artifact(file("artifact1.jar")) {
type = "jar"
}
consumableConfiguration.outgoing.variants.create("secondaryVariant") {
artifact(file("artifact2.jar")) {
type = "secondary-jar"
}
}
And then if you run outgoingVariants
you'll get the following:
> Task :lib1:outgoingVariants
--------------------------------------------------
Variant consumable
--------------------------------------------------
Capabilities
- gradle-sample:lib1:unspecified (default capability)
Attributes
- some.attribute = someValue
Artifacts
- artifact1.jar (artifactType = jar)
Secondary Variants (*)
--------------------------------------------------
Secondary Variant secondaryVariant
--------------------------------------------------
Attributes
- some.attribute = someValue
Artifacts
- artifact2.jar (artifactType = secondary-jar)
Note artifactType = secondary-jar
If you try to consume any of the variants without specifying artifactType it will fail.
So you need to either distinguish artifacts with custom attribute OR using artifactType
artifactType also used with artifact transforms in this article you'll find this code:
dependencies {
artifactTypes.getByName("jar") {
attributes.attribute(minified, false)
}
}
so here artifactType "jar" is associated with "default" attribute "minified" with value "false".
But also this article has two samples, one where they use artifactType for transformations and distinguishing.
Another with auxiliary attribute (minified).
If I recall correctly we decided to go with an auxiliary attribute to provide more "semantics". But we could go with artifactType attribute as well. But I personally would prefer attributes as they more flexible.
Alexander can provide more details.Anton Lakotka [JB]
12/04/2024, 11:36 AM@tapchicoma so if I understood correctly, moko-resources should internally support Kotlin 2.1.0 and configure klibs correctly?unfortunately, yes. if moko resolves KGPs configurations and consume artifacts from then. moko then should be careful with the actual artifact types.
Anton Lakotka [JB]
12/04/2024, 11:37 AMmbonnin
12/04/2024, 1:51 PMAnton Lakotka [JB]
12/04/2024, 3:09 PMLooks like they were designed for this (variants that are not published)Unfortunately it is not so simple 🙂 If you do the custom publication via adhoc software component (article https://docs.gradle.org/current/userguide/publishing_customization.html#sec:publishing-custom-components): like this:
// create an adhoc component
val adhocComponent = softwareComponentFactory.adhoc("myAdhocComponent")
// add it to the list of components that this project declares
components.add(adhocComponent)
// and register a variant for publication
adhocComponent.addVariantsFromConfiguration(outgoing) {
mapToMavenScope("runtime")
}
you can already see the plural form addVariant*s*
here 😉 which means all your variants main + secondary will be published.
to avoid that, one need to "skip" them explicitly like so:
adhocComponent.addVariantsFromConfiguration(outgoing) {
if (this.configurationVariant.name != configuration.name) {
skip()
return@addVariantsFromConfiguration
}
mapToMavenScope("runtime")
}
fortunately names of variants matches with configuration name. so this if
do the trick of filtering 🙂mbonnin
12/04/2024, 3:11 PMAnton Lakotka [JB]
12/04/2024, 3:14 PMmbonnin
12/04/2024, 3:14 PMmbonnin
12/04/2024, 3:15 PMAnton Lakotka [JB]
12/04/2024, 3:16 PMmbonnin
12/04/2024, 3:19 PMAnton Lakotka [JB]
12/04/2024, 3:19 PMAnton Lakotka [JB]
12/04/2024, 3:20 PMmbonnin
12/04/2024, 3:21 PM