【问题标题】:Gradle application plugin with main class in non-main source setGradle 应用程序插件与非主源集中的主类
【发布时间】:2018-06-01 22:48:04
【问题描述】:

文档说

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 是一样的。

【问题讨论】:

    标签: gradle


    【解决方案1】:

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

    UPD:正如 gradle 问题中所建议的那样

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-02
      • 1970-01-01
      相关资源
      最近更新 更多