使用JavaExec和gradle 8定制任务

ifmq2ha2  于 2023-04-06  发布在  Java
关注(0)|答案(1)|浏览(133)

我已经尝试了几种使用JavaExec创建自定义任务的方法。我使用Gradle 8。

tasks {
    val prepareDataset by creating(JavaExec::class) {
        dependsOn("build")

        // set the main class to be executed
        mainClass.set("com.analytic.training.TrainingAppKt")

        // set the arguments to pass to the main method (optional)
        args("--arg1=value1", "--arg2=value2")

        // set the classpath
        // classpath(configurations.getByName("runtimeClasspath"))
        // classpath(jvmRuntimeClasspath)

        // set the task description
        description = "Prepares the training dataset"
        group = "training"
    }
}
task<JavaExec>("prepareDataset2") {
    dependsOn("build")

    // set the main class to be executed
    mainClass.set("com.analytic.training.TrainingAppKt")

    // set the arguments to pass to the main method (optional)
    args("--arg1=value1", "--arg2=value2")

    // set the classpath
    // classpath(configurations.getByName("runtimeClasspath"))
    // classpath(jvmRuntimeClasspath)
    classpath = java.sourceSets["main"].runtimeClasspath

    // set the task description
    description = "Prepares the training dataset"
    group = "training"
}

两者都不行

Unable to find a single main class from the following candidates
[com.analytic.AnalyticApplicationKt, com.analytic.training.TrainingAppKt]

有什么想法吗

drkbr07n

drkbr07n1#

我把dependsOn("build")改成dependsOn("classes")后就能用了,我觉得和spring Boot 冲突了。

task<JavaExec>("prepareDataset") {
    dependsOn("classes")

    // set the main class to be executed
    mainClass.set("com.analytic.training.TrainingAppKt")

    // set the arguments to pass to the main method (optional)
    args("--arg1=value1", "--arg2=value2")

    // set the classpath
    // classpath(configurations.getByName("runtimeClasspath"))
    // classpath(jvmRuntimeClasspath)
    classpath = java.sourceSets["main"].runtimeClasspath

    // set the task description
    description = "Prepares the training dataset"
    group = "training"
}

相关问题