Michael Grigoryan
11/30/2021, 8:21 PMsrc with the following build.gradle.kts fi
le?
plugins {
kotlin("jvm") version "1.6.0"
}
repositories {
mavenCentral()
}
tasks {
sourceSets {
main {
java.srcDirs("src")
}
}
}tapchicoma
11/30/2021, 8:22 PMMichael Grigoryan
11/30/2021, 8:25 PMCasey Brooks
11/30/2021, 8:27 PMfun main(), and then use the application plugin and create separate tasks pointing to each different main function. You'd get the benefit of centralized dependency management and IntelliJ code insights, but the ability to easily run several code files without needing to create multiple Gradle subprojectstapchicoma
11/30/2021, 8:28 PMMichael Grigoryan
11/30/2021, 8:29 PMMichael Grigoryan
11/30/2021, 8:29 PMMichael Grigoryan
11/30/2021, 8:34 PMCasey Brooks
11/30/2021, 8:40 PMsrc/main/kotlin. Something like this should get you started
plugins {
kotlin("jvm")
application
}
val runA by tasks.registering(JavaExec::class) {
classpath = sourceSets.getByName("main").runtimeClasspath
mainClass.set("a.MainKt") // runs the main function in /src/main/kotlin/a/main.kt
}
val runB by tasks.registering(JavaExec::class) {
classpath = sourceSets.getByName("main").runtimeClasspath
mainClass.set("b.MainKt") // runs the main function in /src/main/kotlin/b/main.kt
}
val runC by tasks.registering(JavaExec::class) {
classpath = sourceSets.getByName("main").runtimeClasspath
mainClass.set("c.MainKt") // runs the main function in /src/main/kotlin/c/main.kt
}Michael Grigoryan
11/30/2021, 8:52 PMCasey Brooks
11/30/2021, 9:00 PMrun task. For example:
plugins {
kotlin("jvm")
application
}
val runTask by project.properties
application {
mainClass.set(runTask)
}
and running ./gradlew run -PrunTask=a.MainKt. Or using a when statement within the application configuration block to map a shorter task name to the specific main class, but then you're basically doing the same thing as separate tasks but making it harder to use.Casey Brooks
11/30/2021, 9:03 PMMichael Grigoryan
11/30/2021, 9:16 PM