The impact of maven profiles on spring boot runner?
Hi all,
I'm wondering how the maven and spring profiles are related to each other in IntelliJ. I'm well aware of the difference between a maven profile and a spring profile.
I have a spring boot application for which I have several maven profiles. One such profile is a "withServiceExtension" which adds an extra jar to my artifact as an extension. When running the spring boot application I have replaced the default before launch "Build" task with Run another configuration and selected the maven run config for my artifact which has this withServiceExtension profile enabled.
I'd expect that the result will be that the war in my target directory contains this extra dependency. And when I unzip it, it does look good.
However when running the spring run config, it's not loading the service extension... the only way to achieve this seems to be to activate the withServiceExtension profile inside the maven profiles tool window!
Can someone explain why this is mandatory for the spring runner? and why the maven run config doesn't suffice?
请先登录再写评论。
>I have replaced the default before launch "Build" task with Run another configuration and selected the maven run config for my artifact which has this withServiceExtension profile enabled.
>However when running the spring run config, it's not loading the service extension...
What Run/Debug Configuration type do you use? Do you deploy mentioned war on the application server with e.g. Tomcat Run/Debug Configuration or you are using Spring Boot Run/Debug Configuratoin?
Hi Andrey,
I'm using the maven and spring boot run configurations.
And by default the spring boot run configuration uses the "build" pre launch task. I've replaced it with the maven run config... (which runs: mvn clean install -P withServiceExtension)
Yet this is not enough and I must check the withServieExtension profile in the maven tool window...
To clarify I've attached screenshots of my run configurations
Image 1: maven run config
Image 2: Spring boot run config:
Image 3: Maven tool window profile selection
So I wouldn't expect the maven profile selection in the tool window to have an effect on the spring boot runner... but somehow it does!
Spring Boot Run/Debug Configuration as the classpath uses the module's output directory, specified in the Use classpath of module option. This directory is populated on project build by IDE (and so the currently active profile, specified in Maven projects tool windows is applied for the build) and is most likely not used by the maven goal you have specified in Before launch option.
The module is configured to use a specific module compile output path:<module_dir>/target/classes
(and not inherit the project setting which is <project_root>/out. I've checked but there is no such folder so I'm pretty sure this is not used.
So the output folder is the same as maven's.
>elected the maven run config for my artifact which has this withServiceExtension profile enabled.
May be the issues is related to how the application is packaged and is being run when you build and run by Maven. E.g. how additional extension is added to application when you build by Maven? Is it configured as separate module in IDE?
>I'd expect that the result will be that the war in my target directory contains this extra dependency. And when I unzip it, it does look good.
Note that Spring boot Run/Debug Configuration does not use jar, it uses the module's classpath (consisted from the modules's compiler output) as mentioned.
I see, I've checked the first line of the console when running the spring boot run config and it prints the full list of classes loaded on its classpath. And indeed as expected when the profile is enabled, the dependency in that profile is included, otherwise it's absent.
Now it makes perfect sense to me, just had the wrong assumptions in my head ;-) good to have that cleared. Thanks a lot!
Hi Andrey,
Is there any way to config the active maven profiles("View -> Tool Windows -> Maven") in "Spring Boot Run/Debug Configuration"?
What I want to is when I change another "Spring Boot Run/Debug Configuration", the active maven profiles will change correspondingly. So when I debug the configuration, the running debug classpath would be also changed correspondingly.
Add the appropriate command in the "Before launch" section of the Spring run configuration. See https://i.imgur.com/wI6YlZ3.png
thanks for replying. I have tried, it seems not working. The steps shown in below:
1. Assume I have two maven profile as follows:
2. I have two Spring Boot Run/Debug Configuration: ServerWeb and ServerGis
3. I add "clean install -P ServerGis" in the "Before launch" section of ServerGis's configuration.
4. The current active maven profile is: ServerWeb
5. debug the ServerGis configuration
6. I found "ModuleWeb\target\classes" is still in classpath(show in console log.), but "ModuleGis\target\classes" is not in classpath.
I have to switch the maven profile from ServerWeb to ServerGis manually before debugging to get the correct classpath.
What is the order in run configuration? There is a possibility that build is triggered before the (3) command
No, "clean install" is in the first place.
I have shared an app on github: https://github.com/pcloves/demo , the default active profile is: ServerWeb, and the default run/debug configuration is ServerGis, when clone the project, you can run the configuration: ServerGis directly.
The bad thing you would find is "demo\ModuleWeb\target\classes" is still in the classpath in the first output log of Services --> Console window,
Thanks for the sample, got your point.
Not sure it is possible. Please create a feature request at https://youtrack.jetbrains.com/newIssue?project=IDEA