Reputation: 4591
I'm working with an application that has server-specific attributes defined in a .properties file. The bundled application is regularly to deployed to different Development, UAT and Production servers. Before each deployment however, the bundled properties file must be manually altered to match the server it's being deployed to.
Is there any standardized or automated way to parameterize which server I'm deploying to? i.e., in Jenkins can I specify something like 'mvn package UAT' and it will update my .properties file automagically?
Any input is appreciated, thanks!
Upvotes: 1
Views: 47
Reputation: 2749
The easiest way to do this is with maven profile names. Specifically, create a per-profile properties file in your project, and apply that file as a filter using the profile name and some substitution.
It's split into 2 parts, the profile definition:
<profiles>
<profile>
<id>test</id>
<properties>
<profileName>test</profileName>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<profileName>dev</profileName>
</properties>
</profile>
<profile>
<id>uat</id>
<properties>
<profileName>uat</profileName>
</properties>
</profile>
<profile>
<id>preprod</id>
<properties>
<profileName>preprod</profileName>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileName>prod</profileName>
</properties>
</profile>
</profiles>
And the filter definition:
<build>
<filters>
<filter>src/main/filters/${profileName}.properties</filter>
</filters>
</build>
Additionally, make sure the resource files you want the substitutions performed on are filtered by the maven resource plugin.
Then you're got:
You can then build by using the maven profile name:
mvn package -PUAT
Upvotes: 2