我正在尝试在IntelliJ中的Gradle上创建一个项目并在其上使用JavaFX。
我按照openjfx的建议添加了--module-path${PATH_TO_FX}--add-module javafx.控制,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();
}
}
该应用程序确实执行没有任何错误,但这个弃用警告困扰着我,如果我知道是什么导致了它,我会尝试修复它
这bug:
https://youtrack.jetbrains.com/issue/IDEA-224030
它应该在一些即将到来的版本中得到修复。