Gradle, use material3 in a compose multiplatform project
Asked Answered
R

1

9

I'm doing a project with Jetpack Compose Multiplatform Desktop. I'm not very familiar with Gradle, and I would like to use Material 3 in my project. So, I added this line in build.gradle.kts file:

implementation("androidx.compose.material3:material3:1.0.0-alpha14")

But when I try to import the lib in a Kotlin file with:

import androidx.compose.material3.*

I've got an unresolved reference issue.

This is my build.gradle.kts file:

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

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

group = "com.example"
version = "1.0-SNAPSHOT"

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

kotlin {
    jvm {
        compilations.all {
            kotlinOptions {
                jvmTarget = "18"
                freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
            }
        }
        withJava()
    }
    sourceSets {
        val jvmMain by getting {
            dependencies {
                implementation(compose.desktop.currentOs)
                implementation("androidx.compose.material3:material3:1.0.0-alpha14")
            }
        }
        val jvmTest by getting
    }
}

compose.desktop {
    application {
        mainClass = "MainKt"
        jvmArgs += listOf("-Djava.library.path=./lib")
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "FanControl"
            packageVersion = "1.0.0"
        }
    }
}

I think I should be able to use this lib since the release note indicate it support it.

Edit1: I have this message from Gradle when I try to sync:

Could not resolve: androidx.compose.material3:material3:1.0.0-alpha14
Remote answered 30/11, 2022 at 5:47 Comment(0)
R
13

Finally found what was the problem, it was the wrong library, change

implementation("androidx.compose.material3:material3:1.0.0-alpha14")

with

implementation("org.jetbrains.compose.material3:material3-desktop:1.2.1")
Remote answered 1/12, 2022 at 1:4 Comment(1)
To prevent using the wrong version, you can use implementation(compose.material3)Medicinal

© 2022 - 2024 — McMap. All rights reserved.