chad
chad

Reputation: 7519

Accessing Project Properties from settings.xml

I'm trying to activate a profile in my settings.xml by the value of the pom's groupId. To achieve that I have:

<settings>
    <profiles>
      <profile>
    <id>imf</id>
    <activation>
      <property>
        <name>project.groupId</name>
        <value>myId</value>
      </property>
    </activation>
    <properties>
     . . .
    </properties>
      </profile>
   </profiles>
 </settings>

But this doesn't work. Is it not possible to access project properties from settings? The reference material says you can.

Just to verify my use of the property activator element, I conducted a sanity check using a property set from the command line. Indeed, if I pass in -Dproject.groupId=myId to the mvn command line, my activation works. This leads me to believe that the project properties simply aren't available in the settings.xml file.

Upvotes: 2

Views: 1119

Answers (2)

cserepj
cserepj

Reputation: 926

I had a similar requirement - choosing between profiles depending on the groupId of the project (to choose between remote repositories). Then I noticed that my groupIds are always actually package names in my java class hierarchy. And package names are just simply directories in the filesystem. So my solution to this problem was to use the actication/file/exists tag:

  <profiles>
    <profile>
        <id>client1</id>
        <activation>
            <activeByDefault>false</activeByDefault>
            <file>
                <exists>${basedir}/src/main/java/hu/client1</exists>
            </file>
        </activation>
        <repositories>
            <repository>

            </repository>
        </repositories>
    </profile>
    <profile>
        <id>client2</id>
        <activation>
            <activeByDefault>false</activeByDefault>
            <file>
                <exists>${basedir}/src/main/java/hu/client2</exists>
            </file>
        </activation>
        <repositories>
            <repository>

            </repository>
        </repositories>
    </profile>
    <profile>
        <id>client3</id>
        <activation>
            <activeByDefault>false</activeByDefault>
            <file>
                <exists>${basedir}/src/main/java/com/client3</exists>
            </file>
        </activation>
        <repositories>
            <repository>

           </repository>
        </repositories>
    </profile>
</profiles>

Upvotes: 0

Raghuram
Raghuram

Reputation: 52645

It looks like your specific requirement cannot be achieved in the way you have tried.

project.groupId as a property name (or key) does not mean anything to maven. maven understands (and expands) ${project.groupId} and similar values in settings.xml or pom.xml.

Upvotes: 1

Related Questions