Browse Source
* Improve DSL for setting a custom Compose Plugin Fixes https://github.com/JetBrains/compose-jb/issues/2459 Readme: https://github.com/JetBrains/compose-jb/pull/2526 1. Add `dependencies: Dependencies` extension that is accessible in `compose { }` block 2. Add `Dependencies.compiler` property that can return versions of Compose compiler used by the plugin: ``` compose { kotlinCompilerPlugin.set(dependencies.compiler.forKotlin("1.7.20")) //kotlinCompilerPlugin.set(dependencies.compiler.auto) // determined by applied version of Kotlin. It is a default. } ``` 3. Add ability to set arguments for Compose Compiler. Now we can write: ``` compose { kotlinCompilerPlugin.set(dependencies.compiler.forKotlin("1.7.20")) kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=1.7.21") } ``` 4. Remove checks for different targets We had a separate check for JS, when we released 1.2.0. It doesn't support Kotlin 1.7.20 at that moment. It is hard to refactor this feature in the new code, so I removed it. It is not needed now and it had an ugly code. When we will need it again, we'll write it again. 5. Remove the `compose.tests.androidx.compiler.version` property from gradle.properties and remove `defaultAndroidxCompilerEnvironment` Because they are used only in one test, and it seems there is no reason to use it in another place in the future * Discussionspull/2557/head
Igor Demin
2 years ago
committed by
GitHub
21 changed files with 255 additions and 120 deletions
@ -1,16 +1,20 @@ |
|||||||
package org.jetbrains.compose |
package org.jetbrains.compose |
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType |
private const val KOTLIN_COMPATABILITY_LINK = |
||||||
|
"https://github.com/JetBrains/compose-jb/blob/master/VERSIONING.md#kotlin-compatibility" |
||||||
|
|
||||||
internal object ComposeCompilerCompatability { |
internal object ComposeCompilerCompatability { |
||||||
fun compilerVersionFor(kotlinVersion: String): ComposeCompilerVersion? = when (kotlinVersion) { |
private val kotlinToCompiler = sortedMapOf( |
||||||
"1.7.10" -> ComposeCompilerVersion("1.3.0") |
"1.7.10" to "1.3.0", |
||||||
"1.7.20" -> ComposeCompilerVersion("1.3.2.1") |
"1.7.20" to "1.3.2.1", |
||||||
else -> null |
) |
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
internal data class ComposeCompilerVersion( |
fun compilerVersionFor(kotlinVersion: String): String { |
||||||
val version: String, |
return kotlinToCompiler[kotlinVersion] ?: throw RuntimeException( |
||||||
val unsupportedPlatforms: Set<KotlinPlatformType> = emptySet() |
"This version of Compose Multiplatform doesn't support Kotlin " + |
||||||
|
"$kotlinVersion. " + |
||||||
|
"Please see $KOTLIN_COMPATABILITY_LINK " + |
||||||
|
"to know the latest supported version of Kotlin." |
||||||
) |
) |
||||||
|
} |
||||||
|
} |
||||||
|
@ -0,0 +1,37 @@ |
|||||||
|
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform |
||||||
|
import org.jetbrains.compose.desktop.application.dsl.TargetFormat |
||||||
|
|
||||||
|
plugins { |
||||||
|
id "org.jetbrains.kotlin.jvm" |
||||||
|
id "org.jetbrains.compose" |
||||||
|
} |
||||||
|
|
||||||
|
repositories { |
||||||
|
google() |
||||||
|
jetbrainsCompose() |
||||||
|
} |
||||||
|
|
||||||
|
dependencies { |
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib" |
||||||
|
implementation compose.desktop.currentOs |
||||||
|
} |
||||||
|
|
||||||
|
compose { |
||||||
|
kotlinCompilerPlugin.set(COMPOSE_COMPILER_PLUGIN_PLACEHOLDER) |
||||||
|
kotlinCompilerPluginArgs.add(COMPOSE_COMPILER_PLUGIN_ARGS_PLACEHOLDER) |
||||||
|
|
||||||
|
desktop { |
||||||
|
application { |
||||||
|
mainClass = "Main" |
||||||
|
nativeDistributions { |
||||||
|
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) |
||||||
|
} |
||||||
|
|
||||||
|
def projectPath = project.projectDir.absolutePath |
||||||
|
if (DefaultNativePlatform.currentOperatingSystem.isWindows()) { |
||||||
|
projectPath = projectPath.replace("\\", "\\\\") |
||||||
|
} |
||||||
|
args(projectPath) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Before Width: | Height: | Size: 140 B After Width: | Height: | Size: 140 B |
After Width: | Height: | Size: 140 B |
@ -0,0 +1,11 @@ |
|||||||
|
pluginManagement { |
||||||
|
plugins { |
||||||
|
id 'org.jetbrains.kotlin.jvm' version 'KOTLIN_VERSION_PLACEHOLDER' |
||||||
|
id 'org.jetbrains.compose' version 'COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER' |
||||||
|
} |
||||||
|
repositories { |
||||||
|
mavenLocal() |
||||||
|
gradlePluginPortal() |
||||||
|
} |
||||||
|
} |
||||||
|
rootProject.name = "simple" |
@ -0,0 +1,76 @@ |
|||||||
|
import androidx.compose.foundation.background |
||||||
|
import androidx.compose.foundation.layout.* |
||||||
|
import androidx.compose.foundation.shape.CircleShape |
||||||
|
import androidx.compose.foundation.shape.GenericShape |
||||||
|
import androidx.compose.runtime.Composable |
||||||
|
import androidx.compose.ui.Alignment |
||||||
|
import androidx.compose.ui.ExperimentalComposeUiApi |
||||||
|
import androidx.compose.ui.Modifier |
||||||
|
import androidx.compose.ui.draw.clip |
||||||
|
import androidx.compose.ui.graphics.Color |
||||||
|
import androidx.compose.ui.graphics.Shape |
||||||
|
import androidx.compose.ui.renderComposeScene |
||||||
|
import org.jetbrains.skia.EncodedImageFormat |
||||||
|
import java.io.File |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
object Main { |
||||||
|
@JvmStatic |
||||||
|
@OptIn(ExperimentalComposeUiApi::class) |
||||||
|
fun main(args: Array<String>) { |
||||||
|
val workingDir = args.getOrNull(0)?.let { File(it) } |
||||||
|
workingDir?.mkdirs() |
||||||
|
if (workingDir == null || !workingDir.isDirectory) { |
||||||
|
error("Working directory must be passes as the first argument. '$workingDir' is not a directory") |
||||||
|
} |
||||||
|
|
||||||
|
val image = renderComposeScene(height = 10, width = 10) { |
||||||
|
mainShape() |
||||||
|
} |
||||||
|
val encodedImage = image.encodeToData(EncodedImageFormat.PNG) ?: error("Could not encode image as png") |
||||||
|
workingDir.resolve("main-image.actual.png").writeBytes(encodedImage.bytes) |
||||||
|
|
||||||
|
val mainMethods = this.javaClass.declaredMethods |
||||||
|
.mapTo(TreeSet()) { it.name } |
||||||
|
.joinToString("\n") |
||||||
|
workingDir.resolve("main-methods.actual.txt").writeText(mainMethods) |
||||||
|
} |
||||||
|
|
||||||
|
@Composable |
||||||
|
fun mainShape() { |
||||||
|
triangle(Color.Magenta) |
||||||
|
} |
||||||
|
|
||||||
|
@Composable |
||||||
|
fun unused() { |
||||||
|
transitivelyUnused() |
||||||
|
} |
||||||
|
|
||||||
|
@Composable |
||||||
|
fun transitivelyUnused() { |
||||||
|
triangle(Color.Gray) |
||||||
|
} |
||||||
|
|
||||||
|
@Composable |
||||||
|
fun keptByKeepRule() { |
||||||
|
fillShape(Color.Blue, CircleShape) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Composable |
||||||
|
fun triangle(color: Color) { |
||||||
|
fillShape(color, GenericShape { size, _ -> |
||||||
|
moveTo(size.width / 2f, 0f) |
||||||
|
lineTo(size.width, size.height) |
||||||
|
lineTo(0f, size.height) |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
@Composable |
||||||
|
fun fillShape(color: Color, shape: Shape){ |
||||||
|
Column(modifier = Modifier.fillMaxWidth().wrapContentSize(Alignment.Center)) { |
||||||
|
Box( |
||||||
|
modifier = Modifier.clip(shape).fillMaxSize().background(color) |
||||||
|
) |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue