Skip to content

Commit 07ecc06

Browse files
authored
fix: add <type>klib</type> to native dependencies in POMs (#161)
1 parent 335c898 commit 07ecc06

File tree

1 file changed

+29
-0
lines changed
  • build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl

1 file changed

+29
-0
lines changed

build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
9898

9999
publications.all {
100100
if (this !is MavenPublication) return@all
101+
val publication = this
101102

102103
project.afterEvaluate {
103104
pom {
@@ -123,6 +124,34 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
123124
}
124125

125126
artifact(javadocJar)
127+
128+
// Add <type>klib</type> for Native platform dependencies
129+
if (publication.name in ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES) {
130+
withXml {
131+
val depsNode = asNode().get("dependencies") as? groovy.util.NodeList
132+
if (depsNode == null || depsNode.isEmpty()) {
133+
project.logger.info("No dependencies node found for native publication ${publication.name}")
134+
return@withXml
135+
}
136+
137+
val deps = (depsNode.first() as groovy.util.Node).children()
138+
139+
deps.forEach { dep ->
140+
val node = dep as groovy.util.Node
141+
val artifactId = (node.get("artifactId") as? groovy.util.NodeList)
142+
?.firstOrNull()
143+
?.let { (it as groovy.util.Node).text() }
144+
145+
if (artifactId != null && ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.any { artifactId.endsWith("-$it", ignoreCase = true) }) {
146+
val existingType = node.get("type") as? groovy.util.NodeList
147+
if (existingType == null || existingType.isEmpty()) {
148+
project.logger.info("Adding <type>klib</type> to dependency on $artifactId")
149+
node.appendNode("type", "klib")
150+
}
151+
}
152+
}
153+
}
154+
}
126155
}
127156
}
128157
}

0 commit comments

Comments
 (0)