java - intellij 上使用 javafx 的“替换任务”gradle 弃用警告

标签 java gradle javafx

我正在尝试在 IntelliJ 中的 Gradle 上创建一个项目并在其上使用 JavaFX。

我按照 openjfx 的建议添加了 --module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml ,并按照他们的建议对 build.gradle 应用了更改。

当我运行时,我收到一条弃用警告,指出:

Unnecessarily replacing a task that does not exist has been deprecated. This is scheduled to be removed in Gradle 6.0. Try using create() or register() directly instead. You attempted to replace a task named 'Main.main()', but no task exists with that name already.
    at Main_main___7am0b7lhc2gbw0z3kepxi13tt$_run_closure1$_closure2.doCall(C:\Users\MirAdnan\AppData\Local\Temp\Main_main__.gradle:18)

这是我运行时生成的临时文件:

def gradlePath = ':'
    def runAppTaskName = 'Main.main()'
    def mainClass = 'Main'
    def javaExePath = 'C:/Program Files/Java/jdk-12.0.1/bin/java.exe'
    def _workingDir = 'C:/Users/MirAdnan/IdeaProjects/animation'

    def sourceSetName = 'main'
    def javaModuleName = null





    allprojects {
      afterEvaluate { project ->
        if(project.path == gradlePath && project?.convention?.findPlugin(JavaPluginConvention)) {
          project.tasks.create(name: runAppTaskName, overwrite: true, type: JavaExec) {
            if (javaExePath) executable = javaExePath
            classpath = project.sourceSets[sourceSetName].runtimeClasspath
            main = mainClass
            jvmArgs '--module-path'
jvmArgs 'C:/Program Files/Java/javafx-sdk-12.0.1'
jvmArgs '--add-modules'
jvmArgs 'javafx.controls,javafx.fxml'
jvmArgs '--module-path'
jvmArgs 'C:/Program Files/Java/javafx-sdk-12.0.1'
jvmArgs '--add-modules'
jvmArgs 'javafx.controls,javafx.fxml'

            if(_workingDir) workingDir = _workingDir
            standardInput = System.in
            if(javaModuleName) {
              inputs.property('moduleName', javaModuleName)
              doFirst {
                jvmArgs += [
                  '--module-path', classpath.asPath,
                  '--module', javaModuleName + '/' + mainClass
                ]
                classpath = files()
              }
            }
          }
        }
      }
    }

这是 build.gradle 文件:

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

repositories {
    mavenCentral()
}

dependencies {
    testImplementation group: 'junit', name: 'junit', version: '4.12'
}

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

我只有一个类文件,我不认为这是问题所在:

public class Main extends Application {
    public static void main(String[] args) {
        launch(Main.class, args);
    }
    @Override
    public void start(Stage primaryStage) {
        BorderPane pane = new BorderPane();

        //top
        MenuBar menuBar = new MenuBar();
        Menu exit = new Menu("exit");
        menuBar.setUseSystemMenuBar(true);
        menuBar.getMenus().addAll(exit);
        pane.setTop(menuBar);

        //Scene
        Scene scene = new Scene(pane, 800, 600, Color.BLACK);

        //Stage
        primaryStage.setScene(scene);
        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.show();
    }
}

该应用程序执行时没有任何错误,但这个弃用警告困扰着我,如果我知道导致它的原因,我会尝试修复它

最佳答案

这是已知错误:

https://youtrack.jetbrains.com/issue/IDEA-224030

它应该在一些即将推出的版本中得到修复。

关于java - intellij 上使用 javafx 的“替换任务”gradle 弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57715947/

相关文章:

java - Netbeans OptionsPanelController 按钮焦点

java - Install4j8 对空搜索的处理顺序已更改

groovy - 在 gradle 项目中使用 archivesBaseName 没有效果

java - 转换异常 : Multiple dex files define Lcom/google/android/gms/internal/zzcaw;

java - 无法在 JavaFX JavaScript 中使用 URLClassLoader 加载自定义类

Java 对象重用

java - Concordion 可以将列表作为参数吗?

intellij-idea - 在 gradle 项目和 IntelliJ IDEA 项目中同步更改运行非常缓慢

java - 用户只能选择 JavaFX 之一的图像按钮

css - javafx:在 Pane 上动态更改样式