本文介绍了在IntelliJ上使用javafx``替换任务''gradle弃用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a project on Gradle in IntelliJ and use JavaFX on it.

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

I added --module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml as openjfx suggested and applied changes to build.gradle as they suggested.

我跑步时会收到弃用警告,说明:

when I run I get a deprecation warning stating:

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)

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

And this is the temp file generated when I run:

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文件:

here is the build.gradle file:

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']
}

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

I only have one class file and I don't think it is the problem:

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();
    }
}

该应用确实可以执行,没有任何错误,但是此弃用警告困扰着我,如果我知道是什么原因引起的,我会尝试对其进行修复

The app does execute without any error but this deprecation warning is bugging me and I would try to fix it if I knew what caused it

推荐答案

这是已知的错误:

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

,它应该在即将发布的某些版本中得到修复.

and it should be fixed in some of upcoming versions.

这篇关于在IntelliJ上使用javafx``替换任务''gradle弃用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 16:13