I am trying to get a list of all of the active profiles in maven and use them as a variable in resource filtering.
In particular, when I run something like
mvn package -Pprofile1,profile2
I want to expose the string "profile1,profile2" as a variable in resource filtering.
For example, in my pom.xml file I have the maven war plugin configured as follows to allow resource filtering on everything in the src/main/resources/META-INF directory, and I have a few profiles defined:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<webResources>
<resource>
<directory>src/main/resources</directory>
<!-- Only include the META-INF directory -->
<includes>
<include>META-INF/*</include>
</includes>
<!-- replace placeholder values -->
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
...
<profiles>
<profile>
<id>profile1</id>
<properties>
<environment>profile1</environment>
</properties>
</profile>
<profile>
<id>profile2</id>
<properties>
<environment>profile2</environment>
</properties>
</profile>
Under the META-INF directory, I have a context.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/platform">
<Environment name="spring.profiles.active" value="${environment}" type="java.lang.String" />
</Context>
I tried setting the property "environment" under each profile but the resulting context.xml file only uses the last "environment" variable (e.g. value=profile2).
I also tried using this: value=${project.activeProfiles}
but that returns some sort of list of objects. It would be great if I could iterate over this list and extract the ids from the profiles to build the string, but I couldn't find any documentation in the maven resources plugin on doing this.
What I'm ultimately trying to do is set the spring.profiles.active
variable as an environment variable via the context.xml file, and that variable is the same as the maven build profiles.
src/main/resources
as webResources causesrc/main/resources
is a usual resource which is copied during resource phase and if you like to filter it define it like this... – khmarbaise