问题
I am trying to create a project on Gradle in IntelliJ and use JavaFX on it.
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()
}
}
}
}
}
}
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
回答1:
This is known bug:
https://youtrack.jetbrains.com/issue/IDEA-224030
and it should be fixed in some of upcoming versions.
来源:https://stackoverflow.com/questions/57715947/replacing-a-task-gradle-deprecation-warning-with-javafx-on-intellij