具有非主要源集中的主类的Gradle应用程序插件

时间:2017-12-19 13:23:08

标签: gradle

文档说

  

You can run the application by executing the run task (type: JavaExec). This will compile the main source set, and launch a new JVM with its classes (along with all runtime dependencies) as the classpath and using the specified main class. You can launch the application in debug mode with gradle run --debug-jvm (see JavaExec.setDebug(boolean)).

在我的情况下,主类不在主要的源集中,而是在jmh中(我想快速尝试一些事情,而不使用那里定义的类来通过JMH基础结构)。我还可以使用应用程序插件吗?

只需使用./gradlew :benchmarks:run即可找到"无法找到或加载主要类MyMainClass",如预期的那样。 :jmhRun(与其他任务类比)给出了"任务' jmhRun'没有在项目'基准'"中找到。 :runJmh是一样的。

1 个答案:

答案 0 :(得分:1)

由于main源集的名称在org.gradle.api.plugins.ApplicationPlugin#addRunTask中不可配置,因此仍然是不可能的(5.0版)。我在https://github.com/gradle/gradle/issues/8113那里创建了一个问题。

UPD:在gradle问题中建议

tasks.named('run', JavaExec) {
    classpath = <wanted classpath>
}
相关问题