-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compose Support: GrowingIO Kotlin Compiler Plugin (#29)
* GrowingIO Kotlin Compiler Plugin --------- Co-authored-by: tianhui12 <[email protected]>
- Loading branch information
Showing
12 changed files
with
486 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...-plugin/src/main/kotlin/com/growingio/compose/plugin/GrowingKotlinCompilerGradlePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.growingio.compose.plugin | ||
|
||
import com.growingio.BuildConfig | ||
import org.gradle.api.provider.Provider | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin | ||
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact | ||
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption | ||
|
||
class GrowingKotlinCompilerGradlePlugin : KotlinCompilerPluginSupportPlugin { | ||
override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> { | ||
val project = kotlinCompilation.target.project | ||
return project.provider { | ||
emptyList() | ||
} | ||
} | ||
|
||
override fun getCompilerPluginId(): String = "com.growingio.compose.plugin" | ||
|
||
override fun getPluginArtifact(): SubpluginArtifact { | ||
return SubpluginArtifact( | ||
groupId = "com.growingio", | ||
artifactId = "growingio-compose-plugin", | ||
version = BuildConfig.Version | ||
) | ||
} | ||
|
||
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import com.vanniktech.maven.publish.SonatypeHost | ||
|
||
plugins { | ||
kotlin("jvm") version "1.9.24" | ||
kotlin("kapt") version "1.9.24" | ||
id("distribution") | ||
id("com.vanniktech.maven.publish") version "0.29.0" | ||
id("org.jlleitschuh.gradle.ktlint") version "10.2.1" | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
ktlint { | ||
debug.set(false) | ||
verbose.set(true) | ||
android.set(true) | ||
outputToConsole.set(true) | ||
ignoreFailures.set(false) | ||
enableExperimentalRules.set(true) | ||
filter { | ||
exclude("**/generated/**") | ||
include("**/kotlin/**") | ||
} | ||
} | ||
|
||
val sep = File.separator | ||
distributions { | ||
main { | ||
contents { | ||
from("build${sep}libs") | ||
from("build${sep}publications${sep}maven") | ||
} | ||
} | ||
} | ||
|
||
mavenPublishing { | ||
coordinates("com.growingio", "growingio-compose-plugin", "1.0.0") | ||
|
||
pom { | ||
name.set("growingio-compose-plugin") | ||
description.set("GrowingIO SDK Compose Kotlin Compile Plugin.") | ||
url.set("https://github.com/growingio/growingio-sdk-android-plugin") | ||
licenses { | ||
license { | ||
name.set("The Apache License, Version 2.0") | ||
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") | ||
distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt") | ||
} | ||
} | ||
developers { | ||
developer { | ||
id.set("growingio") | ||
name.set("GrowingIO SDK Team.") | ||
url.set("https://github.com/growingio/") | ||
} | ||
} | ||
scm { | ||
url.set("https://github.com/growingio/growingio-sdk-android-plugin") | ||
connection.set("scm:[email protected]:growingio/growingio-sdk-android-plugin.git") | ||
developerConnection.set("scm:[email protected]:growingio/growingio-sdk-android-plugin.git") | ||
} | ||
} | ||
|
||
publishToMavenCentral(SonatypeHost.S01) | ||
signAllPublications() | ||
|
||
// How to publish | ||
// 1. set mavenCentralUsername=<> mavenCentralPassword=<> in your gradle.properties | ||
// 2. ./gradlew :growingio-compose-plugin:publishToMavenCentral | ||
} | ||
|
||
tasks.named("distZip") { | ||
dependsOn("publishToMavenLocal") | ||
onlyIf { | ||
inputs.sourceFiles.isEmpty.not().also { | ||
require(it) { "No distribution to zip." } | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
google() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
} | ||
|
||
dependencies { | ||
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable") | ||
|
||
kapt("com.google.auto.service:auto-service:1.0.1") | ||
compileOnly("com.google.auto.service:auto-service-annotations:1.0.1") | ||
|
||
testImplementation(kotlin("test-junit")) | ||
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable") | ||
testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.6.0") | ||
testImplementation("org.jetbrains.compose.desktop:desktop:1.6.10") | ||
} | ||
|
||
kapt { | ||
correctErrorTypes = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kotlin.experimental.tryK2=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = ("growingio-compose-plugin") |
28 changes: 28 additions & 0 deletions
28
...pose-plugin/src/main/kotlin/com/growingio/compose/plugin/GrowingIOKotlinCompilerPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.growingio.compose.plugin | ||
|
||
import com.google.auto.service.AutoService | ||
import com.growingio.compose.plugin.compose.JetpackComposeTracingIrExtension | ||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension | ||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys | ||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector | ||
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar | ||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
|
||
@OptIn(ExperimentalCompilerApi::class) | ||
@AutoService(CompilerPluginRegistrar::class) | ||
class GrowingIOKotlinCompilerPlugin : CompilerPluginRegistrar() { | ||
|
||
override val supportsK2: Boolean | ||
get() = true | ||
|
||
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { | ||
val messageCollector = configuration.get( | ||
CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, | ||
MessageCollector.NONE | ||
) | ||
IrGenerationExtension.registerExtension( | ||
extension = JetpackComposeTracingIrExtension(messageCollector) | ||
) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../kotlin/com/growingio/compose/plugin/GrowingIOKotlinCompilerPluginCommandLineProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.growingio.compose.plugin | ||
|
||
import com.google.auto.service.AutoService | ||
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption | ||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor | ||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi | ||
|
||
|
||
@OptIn(ExperimentalCompilerApi::class) | ||
@AutoService(CommandLineProcessor::class) | ||
class GrowingIOKotlinCompilerPluginCommandLineProcessor : CommandLineProcessor { | ||
|
||
override val pluginId: String = "com.growingio.compose.plugin" | ||
|
||
override val pluginOptions: Collection<AbstractCliOption> = emptyList() | ||
|
||
} |
Oops, something went wrong.