java - 在 intellij 上使用 javafx '替换任务' gradle 弃用警告
问题描述
我正在尝试在 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();
}
}
该应用程序确实执行时没有任何错误,但是这个弃用警告让我很烦恼,如果我知道是什么原因导致它,我会尝试修复它
解决方案
推荐阅读
- python - 使用具有可变参数数量的 Scipy curve_fit 进行优化
- sql - 是否有一个 SQL 函数语句在限制范围内返回一个数组并用 * 替换数字以减小大小
- javascript - 使用 laravel 路由链接中的按钮删除产品
- image - 如何从另一个给定图像中恢复图像
- c# - 需要在鼠标位置实例化预制件
- forms - 如何在 AppKit 上的自定义 SwiftUI 表单中右对齐项目标签?
- python - 如何编写python脚本以循环自动填写和提交谷歌表单(描述中的示例链接)说100次
- c# - 如何正确绑定到具有继承的类
- floating-point - 我如何证明 f64::from_bits(0x3fe9000000000000 u64 ) == 0.781250 f64
- excel - 如何在 VBScript 中使用 Excel 工作表函数?