Use MavenRunner and get result (exit code)
已回答
Hello,
I need to run "mvn install". For this I use the next code:
val projectsManager = MavenProjectsManager.getInstance(project)
val explicitProfiles = projectsManager.getExplicitProfiles
val mavenProjects = projectsManager.getRootProjects
val mavenProject: MavenProject = mavenProjects.get(0)
val goals: util.List[String] = new util.ArrayList[String]
goals.add("install")
val parameters = new MavenRunnerParameters(true,
mavenProject.getDirectory,
mavenProject.getFile.getName,
goals,
explicitProfiles.getEnabledProfiles,
explicitProfiles.getDisabledProfiles)
val mavenRunner = MavenRunner.getInstance(project)
mavenRunner.run(parameters, mavenRunner.getSettings, null)
But I also need to get 'mvn install' exit code (result), to be sure that everything worked fine and the plugin can go one.
Could somebody suggest how to get a result from MavenRunner.run() or maybe use some other approach to run mvn install.
Thank you!
Best regards,
Alex.
请先登录再写评论。
Third parameter
will be executed only if exit code is 0. See sources of org.jetbrains.idea.maven.execution.MavenRunner#run on how callback is implemented.
Thank you, Yann!
Is there a way to handle the error? Or get exit code somehow?
You can use your own custom callback, see org.jetbrains.idea.maven.execution.MavenRunner#run to obtain exit code
Thank you, Yann! And I'm sorry. didn't clarify some details.
I tried org.jetbrains.idea.maven.execution.MavenRunner#run earlier. I need to support the version until 2019.1. So the solution for 2019.1 does not work for 2020.1 and the solution for 2020.1 does not work for 2019.1.
Maybe I need to make separate branches for IntelliJ versions?
That is the usual recommendation, unless you can come up with some c/p solution that works in both versions.
Thank you, Yann! 👍