I'm trying to activate profiles of an AppEngine application using the maven command like the following :
mvn appengine:deploy -Dspring.profiles.active=prod
But it is ignored.
Is it possible to activate profiles using maven ?
I'm trying to activate profiles of an AppEngine application using the maven command like the following :
mvn appengine:deploy -Dspring.profiles.active=prod
But it is ignored.
Is it possible to activate profiles using maven ?
I succeeded by linking Maven Profiles to Spring Profiles. In the following I explain how I did :
In pom.xml I identified my maven profiles, and will link them later to spring profiles by storing them in "spring.profiles.to.activate" property :
<!-- PROFILES -->
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.to.active>dev</spring.profiles.to.active>
</properties>
</profile>
<profile>
<id>uat</id>
<properties>
<spring.profiles.to.active>uat</spring.profiles.to.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.profiles.to.active>prod</spring.profiles.to.active>
</properties>
</profile>
</profiles>
I activated filtering in folder ${basedir}/src/main/webapp, by adding maven-war-plugin to build. This will allow us to resolve placeholders ${...} (In this particular case ${spring.profiles.to.activate}) in the mentioned folder.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resources>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resources>
</webResources>
</configuration>
</plugin>
In appengine-web.xml declare the system property : "spring.profiles.active" as being the maven property ${spring.profiles.to.activate}
<appengine-web-app
xmlns="http://appengine.google.com/ns/1.0">
<version>1</version>
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
<system-properties>
<property name="spring.profiles.active" value="${spring.profiles.to.active}" />
</system-properties>
</appengine-web-app>
# Dev
mvn appengine:deploy -Pdev
# UAT
mvn appengine:deploy -Puat
#PROD
mvn appengine:deploy -Pprod
#dev profile, try adding space between -P and dev
mvn appengine:deploy -P dev
#uat profile, try adding space between -P and uat
mvn appengine:deploy -P qa
#prod profile, try adding space between -P and prod
mvn appengine:deploy -P prd