Did anyone manage to run spring boot as a jvm modu...
# multiplatform
s
Did anyone manage to run spring boot as a jvm module of mpp project? build.gradle.kts plugins:
Copy code
id("org.springframework.boot") version "2.2.3.RELEASE"
    kotlin("plugin.spring") version "1.3.61"
    kotlin("plugin.allopen") version "1.3.61"
    kotlin("multiplatform")
    kotlin("kapt")
    id("kotlinx-serialization")


apply(plugin = "io.spring.dependency-management")
sourceSets:
Copy code
sourceSets {
        val jvmMain by getting {
            kotlin.srcDir("src")
            resources.srcDir("resources")
        }
        dependencies {

    implementation(project(":common"))

    implementation("org.springframework.boot:spring-boot-starter-web:2.2.3.RELEASE")
    implementation("org.springframework.boot:spring-boot-configuration-processor:2.2.3.RELEASE")
    configurations["kapt"].dependencies.add(
        DefaultExternalModuleDependency(
            "org.springframework.boot",
            "spring-boot-configuration-processor",
            "2.2.3.RELEASE"
        )
    )
   }
}
Idea doesn’t see generated classes (fun main), theefore I’m running via custom run task:
Copy code
task<JavaExec>("run") {
    main = "com.example.mpp.backend.AppRunner"
    val jvm by kotlin.targets.getting
    val main: KotlinCompilation<KotlinCommonOptions> by jvm.compilations

    val runtimeDependencies = (main as KotlinCompilationToRunnableFiles<KotlinCommonOptions>).runtimeDependencyFiles
    classpath = files(main.output.allOutputs, runtimeDependencies)
}
But dependencies of Spring don’t see application.yml in this case, and therefore app cannot be started
r
I don’t know my way around Spring in particular, but in general it can be helpful to have your multiplatform stuff as a separate module that gets included as a dependency, if you’re having trouble with plugins interfering with each other.
s
It is separate, I’ve tried to do it via multiplatform platform plugin (
kotlin("multiplatform")
for non-multiplatform module as simple way with
kotlin("jvm")
and just
implementation(project(":common"))
, but it did not work - gradle had thought it was an android module (as I have there android target and have enabled android plugin)
r
Hm. Only other thought I have is you might need to do
jvm { withJava() }
instead of
jvm()
for your target declaration to pick up generated Java source if you have the
kotlin("multiplatform")
plugin applied. But if it also wasn’t working with
kotlin("jvm")
then it’s probably something else.
s
there are different problems with kotlin(“multiplatform”): 1. there is a bunch of problems with spring (no bootRun, idea spring run configs don’t work, custom task not using configs, manifest.mf, etc) for kotlin(jvm) I’m currently struggling to make it see common as a JVM module, not as an Android one implementation(path = “common”, configuration = “jvm” or “jvmMain”) didn’t work as well removing android from targets of common module obviously worked is it possible to reference custom target, the one that was done via
val server by creating { dependsOn(jvm) }
?
Well, clean + removing iml worked!
full reimport
r
welp
In that case, another good general tip is to trust gradle and command line before the IDE. Often for more complex configurations, the IDE can misinterpret things but it actually does build from gradle
s
For now, it, AFAIK, works in next order: ./gradlew build Gradle Sync via IDE