Maven profile
When we need to deploy application on multiple platforms like QA, UAT, DEV, Prod.
And according to environment we have properties file which maintain info of db connection or any third party application URL.
In this case if CI/CD implemented our application should be designed in such manner that build will automatically pick the properties file based on the environment.
To achieve this we need to configure maven profile.
Steps to add maven profile
1. Add following in pom.xml
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>uat</id>
<properties>
<activatedProperties>uat</activatedProperties>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
</profiles>
2. Create properties file for each environment like below :
application-dev.properties
application-uat.properties
application-prod.propeties
3 . Add application.properties file containing the below line
spring.profiles.active=@activatedProperties@
Command to make build for particular environment
mvn clean install -P dev // We can provide any environment based on our choice
Steps to add maven profile
1. Add following in pom.xml
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>uat</id>
<properties>
<activatedProperties>uat</activatedProperties>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
</profiles>
2. Create properties file for each environment like below :
application-dev.properties
application-uat.properties
application-prod.propeties
3 . Add application.properties file containing the below line
spring.profiles.active=@activatedProperties@
Command to make build for particular environment
mvn clean install -P dev // We can provide any environment based on our choice
Labels: maven profile, maven profiling, spring boot profile, spring.profiles.active
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home