Reputation:
I am have a java application that has multiple main classes, the build.gradle is written in kotlin and named build.gradle.kts
It is failing with error Build failed with an exception
Script compilation errors:
Line 50: task(runSimple, dependsOn: "classes", type: JavaExec) {
Expecting ')'
I can solve the problem by using build.gradle as shown in Gradle application plugin with multiple main classes
but team want to stay with kotlin
apply plugin: 'java'
task(runSimple, dependsOn: 'classes', type: JavaExec) {
main = 'com.mrhaki.java.Simple'
classpath = sourceSets.main.runtimeClasspath
args 'mrhaki'
systemProperty 'simple.message', 'Hello '
}
is the code when build.gradle is used and it does work,
but
plugins {
java
application
}
task(runSimple, dependsOn: 'classes', type: JavaExec) {
main = 'com.mrhaki.java.Simple'
classpath = sourceSets.main.runtimeClasspath
args 'mrhaki'
systemProperty 'simple.message', 'Hello '
}
does not work
It should be able to run the class com.mrhaki.java.Simple but does not
I guess the kotlin translation is not correct.
Upvotes: 3
Views: 2925
Reputation: 157
if you want debug also then modify task as follows and run with ./gradlew runSimple , taken from gradle: change default port from 5005
no --debug-jvm needed
task("runSimple", JavaExec::class) {
main = "com.mrhaki.java.Simple"
classpath = sourceSets["main"].runtimeClasspath
jvmArgs= listOf( "-Xdebug", "-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y")
}
Upvotes: 2
Reputation:
I finally found execute JavaExec task using gradle kotlin dsl and that helped me. It can be run from command line as ./gradlew runSimple --debug-jvm
group = "com.lapots.breed"
version = "1.0-SNAPSHOT"
plugins {
java
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
}
task("runSimple", JavaExec::class) {
main = "com.mrhaki.java.Simple"
classpath = sourceSets["main"].runtimeClasspath
}
Upvotes: 3