Skip to content

Commit

Permalink
Setup depenedencies in compiler plugin's POM
Browse files Browse the repository at this point in the history
To be able to do composite build, KSP depends on kotlin-compiler rather
than kotlin-compiler-embeddable and uses ShadowJar to relocate some
symbols. Unfortunately, ShadowJar doesn't seem able to relocate the jar
only and generate proper dependencies in the POM. As a workaround, this
commit hard-coded the dependencies.
  • Loading branch information
ting-yuan committed Jan 6, 2021
1 parent be5642b commit 494f7e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun ModuleDependency.includeJars(vararg names: String) {
}
}

// WARNING: remember to update the dependencies in symbol-processing as well.
dependencies {
implementation(kotlin("stdlib", kotlinBaseVersion))
implementation("org.jetbrains.kotlin:kotlin-compiler:$kotlinBaseVersion")
Expand Down
33 changes: 22 additions & 11 deletions symbol-processing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

val kotlinBaseVersion: String by project

plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow") version "6.0.0"
Expand All @@ -10,20 +12,11 @@ val packedJars by configurations.creating

dependencies {
packedJars(project(":compiler-plugin")) { isTransitive = false }
packedJars(project(":api")) { isTransitive = false }
}

tasks.withType<ShadowJar>() {
archiveClassifier.set("")
from(packedJars)
exclude(
"kotlin/**",
"org/intellij/**",
"org/jetbrains/annotations/**",
"META-INF/maven/org.jetbrains/annotations/*",
"META-INF/kotlin-stdlib*"
)

relocate("com.intellij", "org.jetbrains.kotlin.com.intellij")
}

Expand All @@ -34,7 +27,6 @@ tasks {

val sourcesJar by creating(Jar::class) {
archiveClassifier.set("sources")
from(project(":api").sourceSets.main.get().allSource)
from(project(":compiler-plugin").sourceSets.main.get().allSource)
}

Expand All @@ -49,11 +41,30 @@ publishing {
val publication = create<MavenPublication>("shadow") {
artifactId = "symbol-processing"
artifact(tasks["sourcesJar"])
artifact(tasks["shadowJar"])
pom {
name.set("com.google.devtools.ksp:symbol-processing")
description.set("Symbol processing for Kotlin")
// FIXME: figure out how to make ShadowJar generate dependencies in POM,
// or simply depends on kotlin-compiler-embeddable so that relocation
// isn't needed, at the price of giving up composite build.
withXml {
fun groovy.util.Node.addDependency(groupId: String, artifactId: String, version: String, scope: String = "runtime") {
appendNode("dependency").apply {
appendNode("groupId", groupId)
appendNode("artifactId", artifactId)
appendNode("version", version)
appendNode("scope", scope)
}
}

asNode().appendNode("dependencies").apply {
addDependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlinBaseVersion)
addDependency("org.jetbrains.kotlin", "kotlin-compiler-embeddable", kotlinBaseVersion)
addDependency("com.google.devtools.ksp", "symbol-processing-api", version)
}
}
}
}
project.shadow.component(publication)
}
}

0 comments on commit 494f7e9

Please sign in to comment.