简体   繁体   English

如何使用 Gradle 任务运行两个不同的主类

[英]How to run two different Main Classes with a Gradle task

I am pretty new to gradle and unfamiliar with the Groovy language/build script syntax etc.我对 gradle 很陌生,不熟悉 Groovy 语言/构建脚本语法等。

I have one main Class, which starts perfectly fine with我有一个主要的 Class,它的开头非常好

gradle run

But I now want to create a new Task (uitest), which should be called with something like:但是我现在想创建一个新的任务(uitest),应该用类似的东西来调用它:

gradle -q uitest

which should run like above, but with another mainClass.它应该像上面一样运行,但使用另一个 mainClass。

My build script so far looks like this:到目前为止,我的构建脚本如下所示:

plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'

}
mainClassName = 'streetsim.ui.StreetSimApp'

javafx {
    version = "11.0.2"
    modules = ['javafx.controls', 'javafx.fxml']
}

task uitest(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'streetsim.ui.TemporaryUITestPool.main'
}

group 'groupname'
version '1.0-SNAPSHOT'


sourceCompatibility = 11

repositories {
    jcenter()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
}


test {
    useJUnitPlatform()
}

EDIT: I changed the task as following:编辑:我将任务更改如下:

task uitest(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'streetsim.ui.TemporaryUITestPool'
}

And now I get following error:现在我收到以下错误:

Error: JavaFX runtime components are missing, and are required to run this application

As mentioned in the comment to another answer below, I do not want to add VM arguments if possible as I do not want to require a local JavaFX installation正如下面另一个答案的评论中提到的,如果可能的话,我不想添加 VM arguments,因为我不想需要本地 JavaFX 安装

because this FX below are required you need to add the following to the java command (and remove.main as per comment above)因为需要下面的这个 FX,所以您需要将以下内容添加到 java 命令(并根据上面的评论删除.main)

--add-modules javafx.controls,javafx.fxml --module-path <path_to_modules>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM