Skip to content

Commit 8bf72db

Browse files
yigitting-yuan
authored andcommitted
Gradle plugin publishing setup
This CL updates the build to properly publish the gradle plugin with an id to avoid the need to modify settings gradle. After this change, we'll have the following 4 artifacts: symbol-processing-api: same as before symbol-processing: does not include the the gradle-plugin anymore symbol-processing-gradle-plugin: the gradle plugin com.google.devtools.ksp.gradle.plugin: gradle plugin marker artifact After this change, developer can enable KSP by: id("com.google.devtools.ksp") * Still needs to have google as a plugin repository. The gradle plugin publishing model requires publishing a marker artifact so that Gradle can find the main plugin artifact. I've added `java-gradle-plugin` plugin to the gradle-plugin module to enable publishing. Unfortunately, it does have a validation step which fails while traversing kotlin classes in the classpath so I had to disable it. We can enable it once gradle depends on kotlin 1.4. As part of this, I've removed the gradle plugin from the symbol-processing artifact. Instead, it is now published as symbol-processing-gradle-plugin artifact (it is consistent with the project's and androidx's naming scheme but open to changes). For plugin id, I couldn't use symbol-processing because that would require us to publish an artifact with symbol-processing group. Instead, I've picked `com.google.devtools.ksp` which seems close to what AGP does (com.android.application). This way, we can publish the marker artifact in the KSP group. I've made a couple more changes: * Updated gradle to 6.6.1, which is the version kotlin uses * Moved publishing setup to the main gradle file to configure common things (pom, version etc) * Moved the Jar manifest configuration to the main build file so that all artifacts have it (was also a necessary change after unbundling the gradle plugin since it uses that information to find the version). Had to remove `Implementation-Title` as archiveBaseName is depreacted an will be removed in 7. * Added an `outRepo` command line argument to set the repository location for publication. It is handy when testing with a local build. Fixes: #203
1 parent 810917d commit 8bf72db

File tree

6 files changed

+91
-68
lines changed

6 files changed

+91
-68
lines changed

api/build.gradle.kts

-25
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
description = "Kotlin Symbol Processing API"
44

5-
val kspVersion: String by project
6-
7-
group = "com.google.devtools.ksp"
8-
version = kspVersion
9-
105
tasks.withType<KotlinCompile> {
116
kotlinOptions.jvmTarget = "1.8"
127
kotlinOptions.freeCompilerArgs += "-Xjvm-default=compatibility"
@@ -38,27 +33,7 @@ publishing {
3833
pom {
3934
name.set("com.google.devtools.ksp:symbol-processing-api")
4035
description.set("Symbol processing for Kotlin")
41-
url.set("https://goo.gle/ksp")
42-
licenses {
43-
license {
44-
name.set("The Apache License, Version 2.0")
45-
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
46-
}
47-
}
48-
developers {
49-
developer {
50-
name.set("KSP Team")
51-
}
52-
}
53-
scm {
54-
connection.set("scm:git:https://github.com/google/ksp.git")
55-
developerConnection.set("scm:git:https://github.com/google/ksp.git")
56-
url.set("https://github.com/google/ksp")
57-
}
5836
}
5937
}
60-
repositories {
61-
mavenLocal()
62-
}
6338
}
6439
}

build.gradle.kts

+47-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,54 @@ if (!extra.has("kspVersion")) {
1212
}
1313

1414
subprojects {
15+
group = "com.google.devtools.ksp"
16+
version = rootProject.extra.get("kspVersion") as String
1517
repositories {
1618
mavenCentral()
1719
maven("https://dl.bintray.com/kotlin/kotlin-eap")
1820
}
19-
}
21+
tasks.withType<Jar>().configureEach {
22+
manifest.attributes.apply {
23+
put("Implementation-Vendor", "Google")
24+
put("Implementation-Version", project.version)
25+
}
26+
}
27+
pluginManager.withPlugin("maven-publish") {
28+
val publishExtension = extensions.getByType<PublishingExtension>()
29+
publishExtension.repositories {
30+
if (extra.has("outRepo")) {
31+
val outRepo = extra.get("outRepo") as String
32+
maven {
33+
url = File(outRepo).toURI()
34+
}
35+
} else {
36+
mavenLocal()
37+
}
38+
}
39+
publishExtension.publications.whenObjectAdded {
40+
check(this is MavenPublication) {
41+
"unexpected publication $this"
42+
}
43+
val publication = this
44+
publication.pom {
45+
url.set("https://goo.gle/ksp")
46+
licenses {
47+
license {
48+
name.set("The Apache License, Version 2.0")
49+
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
50+
}
51+
}
52+
developers {
53+
developer {
54+
name.set("KSP Team")
55+
}
56+
}
57+
scm {
58+
connection.set("scm:git:https://github.com/google/ksp.git")
59+
developerConnection.set("scm:git:https://github.com/google/ksp.git")
60+
url.set("https://github.com/google/ksp")
61+
}
62+
}
63+
}
64+
}
65+
}

gradle-plugin/build.gradle.kts

+43-6
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,56 @@ tasks.withType<KotlinCompile> {
1212

1313
plugins {
1414
kotlin("jvm")
15+
id("java-gradle-plugin")
16+
`maven-publish`
1517
}
1618

1719
dependencies {
1820
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin-api:$kotlinBaseVersion")
1921
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinBaseVersion")
20-
compileOnly("org.jetbrains.kotlin:kotlin-compiler:$kotlinBaseVersion")
21-
22-
compileOnly(gradleApi())
23-
22+
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinBaseVersion")
2423
testImplementation(gradleApi())
2524
testImplementation("junit:junit:$junitVersion")
2625
}
2726

28-
repositories {
29-
maven("https://dl.bintray.com/kotlin/kotlin-eap")
27+
tasks.named("validatePlugins").configure {
28+
onlyIf {
29+
// while traversing classpath, this hits a class not found issue.
30+
// Disabled until gradle kotlin version and our kotlin version matches
31+
// java.lang.ClassNotFoundException: org/jetbrains/kotlin/compilerRunner/KotlinLogger
32+
false
33+
}
34+
}
35+
36+
gradlePlugin {
37+
plugins {
38+
create("symbol-processing-gradle-plugin") {
39+
id = "com.google.devtools.ksp"
40+
implementationClass = "com.google.devtools.ksp.gradle.KspGradleSubplugin"
41+
description = "Kotlin symbol processing integration for Gradle"
42+
}
43+
}
44+
}
45+
46+
tasks {
47+
val sourcesJar by creating(Jar::class) {
48+
archiveClassifier.set("sources")
49+
from(project.sourceSets.main.get().allSource)
50+
}
51+
}
52+
53+
54+
publishing {
55+
publications {
56+
// the name of this publication should match the name java-gradle-plugin looks up
57+
// https://github.com/gradle/gradle/blob/master/subprojects/plugin-development/src/main/java/org/gradle/plugin/devel/plugins/MavenPluginPublishPlugin.java#L73
58+
this.create<MavenPublication>("pluginMaven") {
59+
artifactId = "symbol-processing-gradle-plugin"
60+
artifact(tasks["sourcesJar"])
61+
pom {
62+
name.set("symbol-processing-gradle-plugin")
63+
description.set("Kotlin symbol processing integration for Gradle")
64+
}
65+
}
66+
}
3067
}

gradle-plugin/src/main/resources/META-INF/gradle-plugins/symbol-processing.properties

-1
This file was deleted.

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
1+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStorePath=wrapper/dists

symbol-processing/build.gradle.kts

-34
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22

3-
description = "Ksp - Symbol processing for Kotlin"
4-
5-
val kspVersion: String by project
6-
7-
group = "com.google.devtools.ksp"
8-
version = kspVersion
9-
103
plugins {
114
kotlin("jvm")
125
id("com.github.johnrengelman.shadow") version "6.0.0"
@@ -16,7 +9,6 @@ plugins {
169
val packedJars by configurations.creating
1710

1811
dependencies {
19-
packedJars(project(":gradle-plugin")) { isTransitive = false }
2012
packedJars(project(":compiler-plugin")) { isTransitive = false }
2113
packedJars(project(":api")) { isTransitive = false }
2214
}
@@ -31,11 +23,6 @@ tasks.withType<ShadowJar>() {
3123
"META-INF/maven/org.jetbrains/annotations/*",
3224
"META-INF/kotlin-stdlib*"
3325
)
34-
manifest.attributes.apply {
35-
put("Implementation-Vendor", "Google")
36-
put("Implementation-Title", baseName)
37-
put("Implementation-Version", project.version)
38-
}
3926

4027
relocate("com.intellij", "org.jetbrains.kotlin.com.intellij")
4128
}
@@ -49,7 +36,6 @@ tasks {
4936
archiveClassifier.set("sources")
5037
from(project(":api").sourceSets.main.get().allSource)
5138
from(project(":compiler-plugin").sourceSets.main.get().allSource)
52-
from(project(":gradle-plugin").sourceSets.main.get().allSource)
5339
}
5440

5541
artifacts {
@@ -66,28 +52,8 @@ publishing {
6652
pom {
6753
name.set("com.google.devtools.ksp:symbol-processing")
6854
description.set("Symbol processing for Kotlin")
69-
url.set("https://goo.gle/ksp")
70-
licenses {
71-
license {
72-
name.set("The Apache License, Version 2.0")
73-
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
74-
}
75-
}
76-
developers {
77-
developer {
78-
name.set("KSP Team")
79-
}
80-
}
81-
scm {
82-
connection.set("scm:git:https://github.com/google/ksp.git")
83-
developerConnection.set("scm:git:https://github.com/google/ksp.git")
84-
url.set("https://github.com/google/ksp")
85-
}
8655
}
8756
}
8857
project.shadow.component(publication)
89-
repositories {
90-
mavenLocal()
91-
}
9258
}
9359
}

0 commit comments

Comments
 (0)