I have a complex multi-module Kotlin multi-platfor...
# gradle
n
I have a complex multi-module Kotlin multi-platform project. It has a
buildSrc
module loading several common Gradle plugins, used by precompiled script plugins:
Copy code
// buildSrc/build.gradle.kts

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10")
    ...
}
The project had no Android support, but now I'd like add the Android plugin as well to one of the sub-modules. It seems that I have to add it to
buildSrc
as well, otherwise I get the error (which seems to be a Gradle classloading conflict):
Copy code
Unable to load class 'com.android.build.gradle.api.BaseVariant'.
So I added it to
buildSrc
as well:
Copy code
// buildSrc/build.gradle.kts

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10")
    ...
    implementation("com.android.tools.build:gradle:8.1.1")
}
Gradle sync now works in Idea but when I try to compile the project, errors like the following appear:
Copy code
Cannot locate tasks that match ':kotlinw:kotlinw-remoting-client-ktor:compileJava' as task 'compileJava' not found in project ':kotlinw:kotlinw-remoting-client-ktor'.
Which I don't understand because the given project is a Kotlin-only project, it has no Java sources, and the Android plugin is not applied to it... Do you have any idea what is happening? Thanks.
x
Which plugins are you applying in your
kotlinw-remoting-client-ktor
Gradle project?
n
It has these plugins applied directly:
Copy code
plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization")
}
And in the root
build.gradle.kts
there is a plugin applied to it in "legacy" style:
Copy code
subprojects {
    ...
    apply(plugin = "maven-publish")
    ...
x
I can see in the Jetbrains Compose Multiplatform template that they're applying both the
kotlin("multiplatform")
plugin and the
id("com.android.library")
ones for their shared module. Can you try adding this last one?
👀 1
n
I removed my Android-related experimentation and tried to add 3 modules (android, desktop, shared) of the template project you suggested. Building the project failed with the same error as before. Then I've realized that if Android artifacts are included in the project, the Idea CTRL+F9 shortcut changes to executing
compileJava
, like
Copy code
Executing tasks: [:buildSrc:compileJava, :buildSrc:testClasses] in project /home/norbi/project/workspace/buildSrc
and
Copy code
Executing tasks: [:kotlinw:kotlinw-remoting-client-ktor:compileJava, ...] in project /home/norbi/project/workspace
So, if I do not build using CTRL+F9 but directly executing
assemble
from the Gradle Tool Window, the build is successful 🙂 Now I have to figure out what should I bind to CTRL+F9 to build the project because
assemble
seems to perform too much operations.
👍🏻 1
Maybe this is the same issue? https://youtrack.jetbrains.com/issue/KTIJ-24048/MPP-project-with-an-android-target-cant-[…]use-of-Task-compileJava-not-found-in-project-common-error I was wondering what makes my project setup so special that this issue arise... at least it seems that most people do not run into this problem.
190 Views