Spring Run Configurations

Answered

Hi, I want to create a new Spring run configuration programmatically.

I managed to do it with Java configurations, but have few issues with Spring:

1. First, without adding Spring jars, I don't have Spring configuration objects. Is there a better way to add the jars other than doing it manually (in my company everyone is using the Ultimate version)?

2. After I added it, I get this error: class com.intellij.spring.boot.run.SpringBootApplicationConfigurationType cannot be cast to class com.intellij.spring.boot.run.SpringBootApplicationConfigurationType (com.intellij.spring.boot.run.SpringBootApplicationConfigurationType is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @6eeea326; com.intellij.spring.boot.run.SpringBootApplicationConfigurationType is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @4b3b0f42)

3. Is there a way to add the configuration as XML programmatically?

My code:

public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
RunManager runManager = RunManager.getInstance(e.getProject());

RunnerAndConfigurationSettings runnerAndConfigurationSettings = runManager.createConfiguration("", new SpringBootApplicationConfigurationType().getDefaultConfigurationFactory());

final SpringBootApplicationRunConfigurationBase applicationConfiguration = (SpringBootApplicationRunConfigurationBase) runnerAndConfigurationSettings.getConfiguration();

applicationConfiguration.setModule(...);
applicationConfiguration.setSpringBootMainClass("...");

runManager.addConfiguration(runnerAndConfigurationSettings);
}

Thanks

 

0
5 comments

1. no

2. did you specify "com.intellij.spring.boot" in <depends> of your plugin.xml? did you add all JARs from Spring Boot plugin?

3. I don't understand this question

0

I did specify now, still get the same error.

0

Please double-check you added Spring/Spring Boot JARs to SDK, not to your plugin classpath http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html

0

re 3, see com.intellij.execution.RunnerAndConfigurationSettings#setShared to share the run configuration

0

I should have added SpringBoot to build.gradle:

intellij {
plugins 'java', 'SpringBoot'
localPath 'C:\\Program Files\\JetBrains\\IntelliJ IDEA 2019.2.2'
}

I'm not sure how and if it will work when I will publish it solves the error.

0

Please sign in to leave a comment.