This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Minimal Gradle project to run a Jetbrains Compose for Desktop
Related issues (and comment): * JetBrains/compose-multiplatform#2309 * JetBrains/compose-multiplatform#2108 (comment) * gradle/gradle#15383
- Loading branch information
0 parents
commit 8090846
Showing
18 changed files
with
533 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# Linux start script should use lf | ||
/gradlew text eol=lf | ||
|
||
# These are Windows script files and should use crlf | ||
*.bat text eol=crlf | ||
|
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,5 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
# Ignore Gradle build output directory | ||
build |
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,9 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
dependencies { | ||
implementation(libs.gradleplugin.kotlin.jvm) | ||
implementation(libs.gradleplugin.jetbrains.compose) | ||
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) | ||
} |
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,10 @@ | ||
dependencyResolutionManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
versionCatalogs { | ||
create("libs") { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} |
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 @@ | ||
import org.gradle.kotlin.dsl.the | ||
|
||
/** | ||
* Workaround for accessing the version catalog from the buildSrc project. | ||
* | ||
* Allows to use libs directly in the kotlin conventions scripts. | ||
* | ||
* Still needed to set in `buildSrc/settings.gradle.kts` | ||
* ```kotlin | ||
* dependencyResolutionManagement { | ||
* versionCatalogs { | ||
* create("libs") { | ||
* from(files("../gradle/libs.versions.toml")) | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* And te following dependency in `buildSrc/build.gradle.kts` | ||
* ```kotlin | ||
* dependencies { | ||
* implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) | ||
* } | ||
* ``` | ||
* | ||
* @see https://github.com/gradle/gradle/issues/15383 | ||
*/ | ||
val org.gradle.api.Project.libs get() = the<org.gradle.accessors.dm.LibrariesForLibs>() |
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 @@ | ||
const val JVM_LANGUAGE_LEVEL = 18 |
39 changes: 39 additions & 0 deletions
39
buildSrc/src/main/kotlin/java-common-conventions.gradle.kts
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,39 @@ | ||
plugins { | ||
java | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
constraints { | ||
// Dependency versions as constraints | ||
} | ||
} | ||
|
||
testing { | ||
suites { | ||
@Suppress("UNUSED_VARIABLE") | ||
val test by getting(JvmTestSuite::class) { | ||
useJUnitJupiter(libs.versions.jupiter.get()) | ||
} | ||
} | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(JVM_LANGUAGE_LEVEL)) | ||
} | ||
} | ||
|
||
tasks.withType<JavaCompile> { | ||
options.encoding = "UTF-8" | ||
options.release.set(JVM_LANGUAGE_LEVEL) | ||
options.compilerArgs = listOf("--enable-preview") | ||
} | ||
|
||
tasks.withType<JavaExec> { | ||
jvmArgs = listOf("--enable-preview") | ||
javaLauncher.set(javaToolchains.launcherFor(java.toolchain)) | ||
} |
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,4 @@ | ||
plugins { | ||
id("java-common-conventions") | ||
`java-library` | ||
} |
33 changes: 33 additions & 0 deletions
33
buildSrc/src/main/kotlin/jetpack-compose-desktop-application-conventions.gradle.kts
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,33 @@ | ||
plugins { | ||
id("java-common-conventions") | ||
kotlin("jvm") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
maven("https://androidx.dev/storage/compose-compiler/repository/") | ||
} | ||
|
||
dependencies { | ||
implementation(compose.desktop.currentOs) | ||
} | ||
|
||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>() { | ||
kotlinOptions.jvmTarget = "$JVM_LANGUAGE_LEVEL" | ||
kotlinOptions.freeCompilerArgs += listOf( | ||
"-Xjvm-default=all", | ||
"-P", | ||
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true", // compat with kotlin 1.7.20-RC | ||
) | ||
} | ||
|
||
// Substitute the compiler to make Compose work with Kotlin 1.7.20-RC | ||
configurations.all { | ||
resolutionStrategy.dependencySubstitution { | ||
substitute(module("org.jetbrains.compose.compiler:compiler")).apply { | ||
using(module(libs.compose.compiler.get().toString())) | ||
} | ||
} | ||
} |
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,13 @@ | ||
plugins { | ||
id("jetpack-compose-desktop-application-conventions") | ||
} | ||
|
||
dependencies { | ||
implementation(project(":gctk-lib")) | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "io.github.bric3.gctk.app.MainKt" | ||
} | ||
} |
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,27 @@ | ||
package io.github.bric3.gctk.app | ||
|
||
import androidx.compose.material.Button | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.window.Window | ||
import androidx.compose.ui.window.application | ||
import kotlin.system.exitProcess | ||
|
||
|
||
fun main() = application { | ||
Window( | ||
title = "GCTK", | ||
onCloseRequest = { | ||
exitProcess(0) | ||
} | ||
) { | ||
val counter = remember { mutableStateOf(0) } | ||
MaterialTheme { | ||
Button(onClick = { counter.value++ }) { | ||
Text("I've been clicked ${counter.value} times") | ||
} | ||
} | ||
} | ||
} |
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,3 @@ | ||
plugins { | ||
id("java-library-conventions") | ||
} |
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,14 @@ | ||
[versions] | ||
jupiter = "5.9.0" | ||
kotlin = "1.7.20-RC" | ||
jetbrains-compose = "1.2.0-alpha01-dev774" | ||
|
||
|
||
[libraries] | ||
# Compose Compiler Version for Kotlin 1.7.20-RC acquired from https://androidx.dev/storage/compose-compiler/repository/ | ||
compose-compiler = { module = "androidx.compose.compiler:compiler", version = "1.4.0-dev-k1.7.20-RC-a143c065804" } | ||
|
||
gradleplugin-kotlin-jvm = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } | ||
gradleplugin-jetbrains-compose = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "jetbrains-compose" } | ||
|
||
[bundles] |
Binary file not shown.
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,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.