Is it possible to force compose compiler version t...
# compose
j
Is it possible to force compose compiler version to 1.5.7 but still using compose multiplatform 1.5.11? I want to have my own subset of compose libraries in androidMain not complies with what CMP offers. Also want to have latest Kotlin versions. Tried enforce this in my convention plugin but not sure if it actually worked, as complain CMP requires Kotlin 1.9.21.
p
You should be able to declare the artifact or version like this
Copy code
compose {
    kotlinCompilerPlugin.set("1.5.7.1")
    // or
    kotlinCompilerPlugin.set("org.jetbrains.compose.compiler:compiler:1.5.7.1")
}
(in the build.gradle.kts file of the module where the
org.jetbrains.compose
plugin is applied)
j
Yeah I know how to add that, but it collides with Compose multiplatform version enforce me to use older version πŸ˜› or how to tell it to be used anyway?
I do have this:
Copy code
class ComposeMultiplatformConventionPlugin : Plugin<Project> {
  override fun apply(target: Project) = with(target) {
    pluginManager.alias(libs.plugins.jetbrains.compose)
    configureCompose()
  }
}

fun Project.configureCompose() {
  compose {
    kotlinCompilerPlugin.set(libs.versions.jetbrains.compose.compiler)
  }

  val composeVersion = libs.versions.jetbrains.compose.asProvider().get()
  configurations.configureEach {
    resolutionStrategy.eachDependency {
      val group = requested.group

      when {
        group.startsWith(libs.plugins.jetbrains.compose.get().pluginId) && !group.endsWith("compiler") -> {
          useVersion(composeVersion)
        }
      }
    }
  }
}

fun Project.compose(block: ComposeExtension.() -> Unit) {
  extensions.configure<ComposeExtension>(block)
}
Also given that I want to use Kotlin 1.9.22 and not 1.9.21 πŸ˜› Whats the magic combo to get out of the crap of all lib versions of compose vs Kotlin not compatible with each other?
p
That part is compose multiplatform, the android snippet to set the compiler plugin would be a different one. If you would like to override the android compose compiler you could do so via
Copy code
android {
    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.8"
    }
}
But I didn't find a way to manually override the android one with the CMP one since that only supports the version as string, not the full maven dependency notation.
j
Basically I want to tell CMP to use the latest androidx variant for ANdroid and the older one for iOS πŸ˜„
p
I'm using Kotlin 1.9.22 with Compose Multiplatform 1.5.11 and Jetbrains Compose Compiler 1.5.7.1 without Issues.
j
Everytime I bump to Kotlin 1.9.22 I get error, CMP 1.5.11 doesnt support Kotlin 19.22, please use 1.9.21 πŸ˜›
I bet it works using this, I just dont understand how to tell CMP to understand this πŸ˜›
p
Have you tried setting it in all your (relevant) gradle modules? Only doing it in shared or androidApp might not be enough.
j
But ok I need to setup Compose kotlin extension for CMP one version and another version for Compose android?
I use convention plugins, so all should be applied to every single module. But sure I couldve missed one πŸ™‚
I will try again and see which module fails.
πŸ‘ 1
Ah gad its my bad, I had an empty module I forgot to delete not actually used but was included in settings πŸ˜„
πŸ‘ 1
Also I did notice I forgot to also update KSP to support, getting warnings: ksp-1.9.21-1.0.15 is too old for kotlin-1.9.22. Please upgrade ksp or downgrade kotlin-gradle-plugin to 1.9.21.
p
I think the part with
Copy code
android {
    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.8"
    }
}
isn't needed, I think it would work by default if the CMP compiler is properly set up but this may be used to force a specific androidx compiler. In my project it works with and without that block. (Kotlin 1.9.22 + Compose Multiplatform 1.6.11)
j
Thats also interesting, cant I select Compose, KSP and Compose CMP versions based on Kotlin version? πŸ˜›
Like here i Kotlin version x, resolve all libs depending on Kotlin version πŸ˜›
p
I haven't worked with KSP in the past 6 Months. But I think that sadly doesn't work (yet).
j
Ah funny also need to setup the reverse version in correct order: e: This version (1.5.4) of the Compose Compiler requires Kotlin version 1.9.21 but you appear to be using Kotlin version 1.9.22 which is not known to be compatible. Please consult the Compose-Kotlin compatibility map located at https://developer.android.com/jetpack/androidx/releases/compose-kotlin to choose a compatible version pair (or
suppressKotlinVersionCompatibilityCheck
but don't say I didn't warn you!). πŸ˜„
KSP works.
Good I am not in a critical mode of developing the app at least πŸ˜›
p
at least for compose it partially works - at least if compose is new enough to know about the newer compiler, but I try to get to the newest kotlin version as soon as possible, so i normally always override the compose compiler version manually before a new compose release comes out. (Jetbrains was significantly faster in the past releases when it comes to releasing a compatible compose compiler for a newly released kotlin version.)
j
Yeah I also heard that they are moving compose compiler out of AOSP, so it will become better soon πŸ™‚
πŸ‘ 1
I think Jetbrains will own it.
The problem is not Jetbrains not faster, the problem is Google πŸ˜›
I wish the entire compose project was open sourced at square or Jetbrains πŸ˜›
And then let Google depend androidx material on jetbrains instead.
K 1
@p-schneider Anyway, do you know if can also cherry pick one compose library to be a more recent version? Imagine I ONLY want to have androidx compose ui version 1.6.0-rc01, but the other libs in compose multiplatform to be using 1.5.4 versions they have?
In similar way override version of compose compiler πŸ™‚
In most cases I prefer using androidx compose BOM; but that also lagging behind in time cant combine it with alpha versions vs rc or stable versions in a nice way.
p
try with
Copy code
implementation("androidx.compose.ui:ui:1.6.0-rc01") {
    exclude(group = "...", module = "...") // to exclude newer dependencies
    // or even
    isTransitive = false
}
I haven't done this myself, but this would be the approach I would try first.
But this could be a lot of pain and a lot of
gradlew :module:dependencies
to figure out what dependency is loaded where etc.
(and I wouldn't try to mix compose 1.5.x with 1.6.x)
j
Ugh ah yeah that will be painful evaluate that and override in Gradle, when Jetbrains Compose already doing same for iOS overloading same package names πŸ˜„
I guess I can wait πŸ˜„
230 Views