Profile file activation in a reactor pom, using paren't relative dir - odd behavior

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Profile file activation in a reactor pom, using paren't relative dir - odd behavior

Danny Shemesh
Hey everyone,

I’m trying to activate a profile in a multi-module project, with several reactor poms, based on a file
existing (or missing) from the parent directory of the root ‘grand’ parent pom.

Here’s a basic example showing what I didn’t accomplish to achieve:

Dir tree:
.
|   activate_me
|
\---parent
    |   pom.xml
    |
    \---child
            pom.xml

Parent pom:
<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <properties>
        <project.parent.relativePath>.</project.parent.relativePath>
        <!— If we don’t declare the above as a prop, the interpolation fails for the parent pom -->
        <activation.file.path>${basedir}/${project.parent.relativePath}/../activate_me</activation.file.path>
        <activated>0</activated>
    </properties>

    <packaging>pom</packaging>
    <groupId>com.fileactivation</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <modules>
        <module>child</module>
    </modules>

    <profiles>
        <profile>
            <id>test-file-activation</id>
            <activation>
                <file>
                    <exists>${activation.file.path}</exists>
                </file>
            </activation>
            <properties>
                <!—I’m trying alter this flag, based on the existence of activation.file.path -->
                <activated>1</activated>
            </properties>
       </profile>
    </profiles>
</project>

Child pom:

<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.fileactivation</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>..</relativePath>
    </parent>

    <packaging>pom</packaging>
    <groupId>com.fileactivation</groupId>
    <artifactId>child</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</project>


Running mvn help:active-profiles, I get:

Active Profiles for Project 'com.fileactivation:parent:pom:0.0.1-SNAPSHOT':
The following profiles are active:
- test-file-activation (source: com.fileactivation:parent:0.0.1-SNAPSHOT)

Active Profiles for Project 'com.fileactivation:child:pom:0.0.1-SNAPSHOT':
The following profiles are active:
<empty>


However, running mvn help:effective-pom, I get:
  <!-- Effective POM for project                                              -->
  <!-- 'com.fileactivation:parent:pom:0.0.1-SNAPSHOT'                         -->
  <!--                                                                        -->
….
    <properties>
      <activated>1</activated>
      <activation.file.path>c:\Work\file-activation\parent/./../activate_me</activation.file.path>

  <!-- Effective POM for project                                              -->
  <!-- 'com.fileactivation:child:pom:0.0.1-SNAPSHOT'                          -->
  <!--                                                                        -->
    <properties>
      <activated>0</activated> <-- The file path below is correct, I expected it would be activated here -->
      <activation.file.path>C:\Work\file-activation\parent\child/../../activate_me</activation.file.path>


It seems like the activation file path is expanded correctly in the child module, however, it does not
activate the profile as I would’ve expected;
Sadly, using session.executionRootDirectory, or maven.multiModuleProjectDirectory wouldn’t meet all
Our requirements, as we have several parent poms, and we don’t always run maven from the ‘grand’ pom directory.

The above was tested using maven 3.6.3 on windows.

Would love to have any pointers on why this doesn’t work, and how can I achieve such a behavior irregardless.

Thanks a ton,
Danny