• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication
2 
3 plugins {
4     `java-platform`
5 }
6 
7 val name = project.name
8 
<lambda>null9 dependencies {
10     constraints {
11         rootProject.subprojects.forEach {
12             if (it.name == name) return@forEach
13             if (!it.plugins.hasPlugin("maven-publish")) return@forEach
14             evaluationDependsOn(it.path)
15             it.publishing.publications.all {
16                 this as MavenPublication
17                 if (artifactId.endsWith("-kotlinMultiplatform")) return@all
18                 if (artifactId.endsWith("-metadata")) return@all
19                 // Skip platform artifacts (like *-linuxx64, *-macosx64)
20                 // It leads to inconsistent bom when publishing from different platforms
21                 // (e.g. on linux it will include only linuxx64 artifacts and no macosx64)
22                 // It shouldn't be a problem as usually consumers need to use generic *-native artifact
23                 // Gradle will choose correct variant by using metadata attributes
24                 if (artifacts.any { it.extension == "klib" }) return@all
25                 this@constraints.api(mapOf("group" to groupId, "name" to artifactId, "version" to version))
26             }
27         }
28     }
29 }
30 
<lambda>null31 publishing {
32     publications {
33         val mavenBom by creating(MavenPublication::class) {
34             from(components["javaPlatform"])
35         }
36         // Disable metadata publication
37         forEach { pub ->
38             pub as DefaultMavenPublication
39             pub.unsetModuleDescriptorGenerator()
40             tasks.matching { it.name == "generateMetadataFileFor${pub.name.capitalize()}Publication" }.all {
41                 onlyIf { false }
42             }
43         }
44     }
45 }
46 
unsetModuleDescriptorGeneratornull47 fun DefaultMavenPublication.unsetModuleDescriptorGenerator() {
48     @Suppress("NULL_FOR_NONNULL_TYPE")
49     val generator: TaskProvider<Task?> = null
50     setModuleDescriptorGenerator(generator)
51 }
52