Repository navigation
Add compiler lowering for Compose HTML EAP SSR #5769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Clemens Koprolin (clemenskoprolin)
merged 7 commits into
master
from
clemenskoprolin/compose-html-ssr-lowering
Oct 27, 2026
+9,972
−475
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3920c29
Add Compose HTML SSR compiler lowering
clemenskoprolin cd4a45c
Share HTML serialization helpers and integrate the compiler build
clemenskoprolin c1d83a5
Applying reformatting
clemenskoprolin b6d52a7
Use direct HTML writer regions for composable text
clemenskoprolin 269bb19
Lower special HTML elements directly to the SSR writer
clemenskoprolin c2123ea
Fix settings.gradle.kts conflict
clemenskoprolin b96194f
Move HTML compiler test samples into a dedicated package
clemenskoprolin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| # Compose HTML compiler plugin | ||
|
|
||
| Prepares static HTML at compile time to reduce work during server-side rendering. | ||
|
|
||
| ## Activate | ||
|
|
||
| Use the [Compose HTML EAP runtime](../README.md#published-artifacts). | ||
| Add the plugin to your module's `build.gradle.kts` alongside your existing Kotlin and Compose compiler plugins: | ||
|
|
||
| ```kotlin | ||
| plugins { | ||
| id("org.jetbrains.compose.html.lowering") version "<version>" | ||
| } | ||
| ``` | ||
|
|
||
| Lowering is enabled for JVM targets. | ||
| The Gradle plugin adds the compiler plugin and sets the required compiler order. | ||
|
|
||
| ### Using a local checkout | ||
|
|
||
| To resolve both plugins from source, add these entries to your project's `settings.gradle.kts`: | ||
|
|
||
| ```kotlin | ||
| pluginManagement { | ||
| includeBuild("/path/to/html/eap/compiler-plugin/gradle-plugin") | ||
| // Keep your existing plugin repositories here. | ||
| } | ||
|
|
||
| includeBuild("/path/to/html") | ||
| ``` | ||
|
|
||
| For the local EAP runtime setup, see the [EAP README](../README.md). | ||
|
|
||
| ## Configure | ||
|
|
||
| Optional settings in your module's `build.gradle.kts`: | ||
|
|
||
| ```kotlin | ||
| import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType | ||
|
|
||
| htmlLowering { | ||
| enabledTargets.set(setOf(KotlinPlatformType.jvm, KotlinPlatformType.androidJvm)) | ||
| } | ||
| ``` | ||
|
|
||
| Currently, only JVM rendering is supported. Set it to `emptySet()` to disable lowering for all targets. |
This file contains hidden or 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,57 @@ | ||
| /* | ||
| * Copyright 2026 JetBrains s.r.o. and respective authors and developers. | ||
| * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
| */ | ||
|
|
||
| import java.util.Properties | ||
|
|
||
| plugins { | ||
| kotlin("jvm") | ||
| } | ||
|
|
||
| val pluginProperties = Properties().apply { | ||
| file("plugin.properties").inputStream().use(::load) | ||
| } | ||
| val kotlinVersion = Properties().apply { | ||
| rootProject.file("buildSrc/gradle.properties").inputStream().use(::load) | ||
| }.getProperty("kotlin.version") | ||
|
|
||
| group = "org.jetbrains.compose.html" | ||
| version = pluginProperties.getProperty("version") | ||
|
|
||
| val compilerPluginPath = path | ||
| subprojects { | ||
| // Resolve the compiler artifact from this build while developing the Gradle plugin. | ||
| configurations.configureEach { | ||
| resolutionStrategy.dependencySubstitution { | ||
| substitute(module("org.jetbrains.compose.html:compose-html-compiler-plugin")) | ||
| .using(project(compilerPluginPath)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // The HTML root build targets JVM 11. Gradle requires Java to use the same target. | ||
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":internal-html-serialization-eap")) | ||
| compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion") | ||
| } | ||
|
|
||
| publishing { | ||
| publications { | ||
| create<MavenPublication>("maven") { | ||
| from(components["java"]) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.named("check") { | ||
| dependsOn( | ||
| "$compilerPluginPath:tests:check", | ||
| gradle.includedBuild("compose-html-lowering-gradle-plugin").task(":test") | ||
| ) | ||
| } |
This file contains hidden or 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,63 @@ | ||
| /* | ||
| * Copyright 2026 JetBrains s.r.o. and respective authors and developers. | ||
| * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
| */ | ||
|
|
||
| import java.util.Properties | ||
| import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
|
|
||
| plugins { | ||
| kotlin("jvm") | ||
| `java-gradle-plugin` | ||
| } | ||
|
|
||
| val pluginProperties = Properties().apply { | ||
| file("../plugin.properties").inputStream().use(::load) | ||
| } | ||
| val kotlinVersion = Properties().apply { | ||
| file("../../../buildSrc/gradle.properties").inputStream().use(::load) | ||
| }.getProperty("kotlin.version") | ||
|
|
||
| group = "org.jetbrains.compose.html" | ||
| version = pluginProperties.getProperty("version") | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| // The HTML root build targets JVM 11. Gradle requires Java to use the same target. | ||
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
|
|
||
| kotlin { | ||
| compilerOptions { | ||
| jvmTarget.set(JvmTarget.JVM_11) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin-api:$kotlinVersion") | ||
| testImplementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") | ||
| testImplementation(kotlin("test-junit")) | ||
| } | ||
|
|
||
| gradlePlugin { | ||
| plugins { | ||
| create("htmlLowering") { | ||
| id = pluginProperties.getProperty("id") | ||
| implementationClass = "org.jetbrains.compose.html.gradle.HtmlLoweringGradlePlugin" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.test { | ||
| // Gradle ProjectBuilder injects synthetic classes through java.lang on JDK 21. | ||
| jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") | ||
| } | ||
|
|
||
| // The plugin needs its coordinates after it has been packaged and installed elsewhere. | ||
| tasks.processResources { | ||
| from("../plugin.properties") { rename { "compose-html-lowering.properties" } } | ||
| } |
19 changes: 19 additions & 0 deletions
19
html/eap/compiler-plugin/gradle-plugin/settings.gradle.kts
This file contains hidden or 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,19 @@ | ||
| /* | ||
| * Copyright 2026 JetBrains s.r.o. and respective authors and developers. | ||
| * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
| */ | ||
|
|
||
| pluginManagement { | ||
| val kotlinVersion = java.util.Properties().apply { | ||
| file("../../../buildSrc/gradle.properties").inputStream().use(::load) | ||
| }.getProperty("kotlin.version") | ||
| plugins { | ||
| kotlin("jvm") version kotlinVersion | ||
| } | ||
| repositories { | ||
| gradlePluginPortal() | ||
| mavenCentral() | ||
| } | ||
| } | ||
|
|
||
| rootProject.name = "compose-html-lowering-gradle-plugin" |
27 changes: 27 additions & 0 deletions
27
.../gradle-plugin/src/main/kotlin/org/jetbrains/compose/html/gradle/HtmlLoweringExtension.kt
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Copyright 2026 JetBrains s.r.o. and respective authors and developers. | ||
| * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
| */ | ||
|
|
||
| package org.jetbrains.compose.html.gradle | ||
|
|
||
| import org.gradle.api.provider.SetProperty | ||
| import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType | ||
|
|
||
| /** | ||
| * Configures HTML lowering for Kotlin compilations. Enabled by default for JVM targets. | ||
| * | ||
| * ```kotlin | ||
| * htmlLowering { | ||
| * enabledTargets.set(setOf(KotlinPlatformType.jvm, KotlinPlatformType.androidJvm)) | ||
| * } | ||
| * ``` | ||
| */ | ||
| abstract class HtmlLoweringExtension { | ||
| /** | ||
| * Kotlin platform types for which lowering is enabled. Defaults to [KotlinPlatformType.jvm]. | ||
| * Set to an empty set to disable lowering for all targets. | ||
| * Enabling an unsupported compiler platform reports a warning and skips lowering. | ||
| */ | ||
| abstract val enabledTargets: SetProperty<KotlinPlatformType> | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep just one property?
With Jvm enabled by default