2020-07-07 07:18:10 -04:00
|
|
|
apply plugin: "application"
|
|
|
|
|
|
|
|
description = "Java MainClass execution examples"
|
|
|
|
|
|
|
|
ext {
|
|
|
|
javaMainClass = "com.baeldung.gradle.exec.MainClass"
|
|
|
|
}
|
|
|
|
|
|
|
|
jar {
|
|
|
|
manifest {
|
|
|
|
attributes(
|
|
|
|
"Main-Class": javaMainClass
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2024-01-15 13:57:48 -05:00
|
|
|
sourceCompatibility = "1.8"
|
|
|
|
targetCompatibility = "1.8"
|
2020-07-07 07:18:10 -04:00
|
|
|
|
|
|
|
application {
|
|
|
|
mainClassName = javaMainClass
|
|
|
|
}
|
|
|
|
|
|
|
|
task runWithJavaExec(type: JavaExec) {
|
|
|
|
group = "Execution"
|
|
|
|
description = "Run the main class with JavaExecTask"
|
|
|
|
classpath = sourceSets.main.runtimeClasspath
|
|
|
|
main = javaMainClass
|
|
|
|
}
|
|
|
|
|
|
|
|
task runWithExec(type: Exec) {
|
|
|
|
dependsOn build
|
|
|
|
group = "Execution"
|
|
|
|
description = "Run the main class with ExecTask"
|
|
|
|
commandLine "java", "-classpath", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass
|
|
|
|
}
|
|
|
|
|
|
|
|
task runWithExecJarExecutable(type: Exec) {
|
|
|
|
dependsOn jar
|
|
|
|
group = "Execution"
|
|
|
|
description = "Run the output executable jar with ExecTask"
|
|
|
|
commandLine "java", "-jar", jar.archiveFile.get()
|
|
|
|
}
|
|
|
|
|
|
|
|
task runWithExecJarOnClassPath(type: Exec) {
|
|
|
|
dependsOn jar
|
|
|
|
group = "Execution"
|
|
|
|
description = "Run the mainClass from the output jar in classpath with ExecTask"
|
|
|
|
commandLine "java", "-classpath", jar.archiveFile.get() , javaMainClass
|
|
|
|
}
|