Lazaruss
Lazaruss

Reputation: 1237

Maven profiles with variable for properties

I am studying MAVEN profiles and i have a question about seting properties with variables. At the moment, i am using the following configuration :

<profile>
  <id>Action type D restriction</id>
  <activation>
    <property>
      <name>actionType</name>
      <value>D</value>
    </property>
  </activation>
  <properties>
    <restriction.actionType>D</restriction.actionType>
  </properties>
</profile>

<profile>
  <id>Action type W restriction</id>
  <activation>
    <property>
      <name>actionType</name>
      <value>W</value>
    </property>
  </activation>
  <properties>
    <restriction.actionType>W</restriction.actionType>
  </properties>
</profile>

My question is this ; is it possible to somehow use one profile with a variable to do the same job, something along the lines of :

<profile>
  <id>Action type restriction</id>
  <activation>
    <property>
      <name>actionType</name>
      <value>[D,W]</value>
    </property>
  </activation>
  <properties>
    <restriction.actionType>${project.profiles.profile.activation.value}</restriction.actionType>
  </properties>
</profile>

Or something along those lines.

Upvotes: 3

Views: 6232

Answers (2)

Lazaruss
Lazaruss

Reputation: 1237

Thank you Tunaki. That did the trick. Now my setup is this :

<project>
...
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <ActionType/>
</properties>
...
<profiles>
    <profile>
        <id>Action-type profile</id>
        <activation>
            <property>
                <name>actionType</name>
                <value>[D,W]</value>
            </property>
        </activation>
    </profile>
</profiles>
...
<build>
    <pluginManagement>
      <plugins>
        <plugin>
            <groupId>properties.plugin</groupId>
            <artifactId>Lazaruss-maven-plugin</artifactId>
            <version>1.0-SNAPSHOT</version>

            <configuration>
                <actionType>${actionType}</actionType>
            </configuration>
            ...
        </plugin>
      </plugins>
    </pluginManagement>
</build>

And running it with command :

mvn groupId:artefactId:version:goal -DactionType=W

It sets the variable in my class to W now :)

PS : notice that the variable in my class is also named 'actionType'

Upvotes: 0

michaldo
michaldo

Reputation: 4599

Maybe you want something like this

<profiles>
    <profile>
        <id>Action type restriction</id>
        <activation>
            <property>
                <name>actionType</name>
            </property>
        </activation>
        <properties>
            <restriction.actionType>${actionType}</restriction.actionType>
        </properties>
    </profile>
</profiles>

Upvotes: 3

Related Questions