So I am building a spring boot web application, packaging as a war, and deploying to a tomcat application server.
I have the following dependency in my pom.xml for tomcat:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
The scope of this dependency needs to be provided in order to be able to deploy it to a tomcat instance. However, when I want to run the war via the spring boot CLI or via IntelliJ's default spring boot run configuration, I need to remove the <scope>provided</scope>
in order for it to run the embedded tomcat.
My question is, is there some way to make the dependency conditionally provided based on an active spring profile, or some other method?
Within each profile element, we can configure many elements such as dependencies, plugins, resources, finalName. So, for the example above, we could add plugins and their dependencies separately for integration-tests and mutation-tests.
You can't control dependencies via spring profiles. However you can control spring profiles by maven profiles and it can solve your problem.
You can declare several maven profiles in your application and provide different set of dependencies for each of them. Then you can configure maven profiles to use particular spring profile. Take a look on maven profiles and an example of such configuration in this thread
In your specific case, you can just do : In the dependencies to run spring-boot with embedded tomcat :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
And in a profile to deploy under tomcat
<profile>
<id>tomcat</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
After, to build for a specific profile
mvn clean install -Ptomcat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With