In a Gradle project with many modules, some MPP an...
# multiplatform
r
In a Gradle project with many modules, some MPP and some JVM only, how can I add a dependency in a JVM module to the JVM part of a MPP module? This produces an error:
Copy code
implementation(project(":path:to:mpp-module"))
Copy code
WARNING: Ignoring dependency of module 'mpp-module' on module 'jvm-module'. Java modules cannot depend on Android modules
g
Looks that it's Android module, not JVM
r
No
g
At least this warning says about this
Maybe a bug
r
The error is pretty clear and absolutely doesn’t say that?
It sees the MPP project as an Android one instead of looking for the JVM module
g
It's not an error, it's a warning
But yeah, I mean, it may be a bug for sure
r
“Just a warning” that completely prevents IntelliJ from reading the project
g
Yes, but it's not a compilation error as I understand, which itself looks like a bug
r
I managed to make it work, kinda. I cleaned the entire this and reimported it in IntelliJ. The warning is still there but no longer prevents me from working
I really need a workaround on this. Is there no way to add a specific artifact of another module as dependency?
g
I would just recommend to create a sample project with reproduction of this bug and report an issue
l
@ribesg Does your
mpp-module
target Android?
r
Yes, like all of them. I think I’ve seen multiple open issues close to the once I have
I just have Android+iOS+JVM modules and JVM modules.
One solution I can think of is, maybe I can make my JVM modules MPP with just a JVM target?
l
That's why. You need to either use a
jvm
target if possible, or add an android target to your module having the dependency
r
I have both @louiscad
The problem is a
kotlin-jvm
module depending on a
kotlin-multiplatform
module having both
android
and
jvm
targets is throwing this “warning”
l
Can you show me the
plugins { … }
snippet from your consuming module?
r
Copy code
plugins {
    kotlin
    serialization
}
(I have this extension)
Copy code
inline val PluginDependenciesSpec.serialization: PluginDependencySpec
    get() = id("kotlinx-serialization").version(Versions.kotlin)
l
It needs to target Android too:
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.library")
}
r
But I don’t want it to
It’s a backend module
l
First, you should report the issue (kotl.in/issue), be clear that the JVM-only backend module depends on a multiplatform module targeting both JVM and Android. Then, for workarounds, you have at least these two choices: 1. Publish your
mpp-module
as a library to mavenLocal (or another repository if you want), and depend on that maven dependency from your JVM-backend only module. 2. Remove the dependency on Android from your
mpp-module
, and use the Android APIs in another module depending on it.
👍 1
r
These are not acceptable solutions. I’m gonna try to transform my JVM module into a multiplatform module with only JVM target
That doesn’t work either. Damn. I’m just not changing my entire project architecture because of a bug. I guess we’ll have to work without IDE until this gets fixed.
l
@ribesg My solution #1 doesn't require changing the architecture. Only applying the
maven-publish
plugin and setting up the artifact names if you want. I have experience and examples customizing or disabling unneeded publications, I can help if you need it.
r
I already have the
maven-publish
plugin applied on the entire thing.
I guess I could define a custom build task that first publishes those problematic mpp modules to maven local, then run the actual full publish
You would still need to publish any change to maven local every time
l
Yes (to both)
r
As stated in the issue report, the problem occurs when reopening a project. I just tried removing all
.gradle
build
.idea
*.iml
files and reimporting the project, and IntelliJ now works as expected in all files of the project. I’ll just have to do that every time I add a new module to the project I guess, it’s good enough. Adding that to the issue.
👍 1