-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathbuild.gradle.kts
55 lines (50 loc) · 2.03 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication
import java.util.Locale
plugins {
id("java-platform")
}
val name = project.name
dependencies {
constraints {
rootProject.subprojects.forEach {
if (unpublished.contains(it.name)) return@forEach
if (it.name == name) return@forEach
if (!it.plugins.hasPlugin("maven-publish")) return@forEach
evaluationDependsOn(it.path)
it.publishing.publications.all {
this as MavenPublication
if (artifactId.endsWith("-kotlinMultiplatform")) return@all
if (artifactId.endsWith("-metadata")) return@all
// Skip platform artifacts (like *-linuxx64, *-macosx64)
// It leads to inconsistent bom when publishing from different platforms
// (e.g. on linux it will include only linuxx64 artifacts and no macosx64)
// It shouldn't be a problem as usually consumers need to use generic *-native artifact
// Gradle will choose correct variant by using metadata attributes
if (artifacts.any { it.extension == "klib" }) return@all
[email protected](mapOf("group" to groupId, "name" to artifactId, "version" to version))
}
}
}
}
publishing {
publications {
val mavenBom by creating(MavenPublication::class) {
from(components["javaPlatform"])
}
// Disable metadata publication
forEach { pub ->
pub as DefaultMavenPublication
pub.unsetModuleDescriptorGenerator()
tasks.matching {
it.name == "generateMetadataFileFor${ pub.name.replaceFirstChar { it.uppercaseChar() } }Publication"
}.all {
onlyIf { false }
}
}
}
}
fun DefaultMavenPublication.unsetModuleDescriptorGenerator() {
@Suppress("NULL_FOR_NONNULL_TYPE")
val generator: TaskProvider<Task> = null
setModuleDescriptorGenerator(generator)
}