I've created simple build.gradle.kts
file
group = "com.lapots.breed"
version = "1.0-SNAPSHOT"
plugins { java }
java { sourceCompatibility = JavaVersion.VERSION_1_8 }
repositories { mavenCentral() }
dependencies {}
task<JavaExec>("execute") {
main = "com.lapots.breed.Application"
classpath = java.sourceSets["main"].runtimeClasspath
}
In src/main/java/com.lapots.breed
I created Application
class with main method
package com.lapots.breed;
public class Application {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
But when I try to execute execute
tasks it fails with the error that task doesn't exist. Also when I list all the available tasks using gradlew tasks
it doesn't show execute
task at all.
What is the problem?
The following build script should work (Gradle 4.10.2
, Kotlin DSL 1.0-rc-6
):
group = "com.lapots.breed"
version = "1.0-SNAPSHOT"
plugins {
java
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
}
task("execute", JavaExec::class) {
main = "com.lapots.breed.Application"
classpath = sourceSets["main"].runtimeClasspath
}
According the not-listed task - from certain version, Gradle doesn't show custom tasks which don't have assigned AbstractTask.group. You can either list them via gradle tasks --all
, or set the group
property on the given task(s), e.g.:
task("execute", JavaExec::class) {
group = "myCustomTasks"
main = "com.lapots.breed.Application"
classpath = sourceSets["main"].runtimeClasspath
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With