Arrowsome
Arrowsome

Reputation: 2859

Adding Jetbrains Compose to Kotlin/JVM Desktop build.gradle (Groovy)

With no sample on how to add compose (desktop, no KMP involved) to build.gradle (Groovy) file I'm not sure which and how to add the dependencies required:

plugins {
    ...
    id "org.jetbrains.compose" version "1.5.11"
}

however, in build.gradle.kts it's similar to:

plugins {
    ...
    id("org.jetbrains.compose")
}

...

repositories {
    ...
    maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

dependencies {
    ...
    implementation(compose.desktop.currentOs)
}

Basically, how to convert the kts version to Groovy one?

Upvotes: 1

Views: 103

Answers (1)

Mahozad
Mahozad

Reputation: 24612

I successfully ran a simple app with the below build.gradle (Groovy) file with Gradle 8.10.

It's mostly the same as the Kotlin DSL except for the maven {...} part.

import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    id("org.jetbrains.kotlin.jvm")
    id("org.jetbrains.compose")
    // OR to specify the version of the plugin:
    // id("org.jetbrains.compose") version "1.6.11"
}

repositories {
    maven { url("https://maven.pkg.jetbrains.space/public/p/compose/dev") }
    // OR as a shortcut, replace the above line with jetbrainsCompose()
}

dependencies {
    implementation(compose.desktop.currentOs)
}

compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Exe)
            packageVersion = "1.0.0"
            packageName = project.name
            buildTypes.release.proguard {
                version = "7.5.0"
            }
        }
    }
}

A few notes:

  • Groovy can denote strings with either ' or "
  • Parentheses for function/method calls can be omitted
    Hence, url "something" is equivalent to url("something")

Upvotes: 0

Related Questions