Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not append system properties from profile config

I have build configuration for maven failsafe plugin which includes systemPropertyVariables:

<build>
  <plugins>
    <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.19.1</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <systemPropertyVariables>
            <buildDirectory>${project.build.directory}</buildDirectory>
          </systemPropertyVariables>
        </configuration>
      </plugin>
  </plugins>
</build>

Also I have a profile which can append few properties to same plugin via pluginManagement:

<profile>
  <id>test</id>
  <activation>
    <property>
      <name>test.host</name>
    </property>
  </activation>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <TEST_HOST>test.host</TEST_HOST>
            </systemPropertyVariables>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</profile>

But I can't read properties from this profile. It's working fine if I delete systemPropertyVariables in build plugin configuration section and keep in pluginManagement configuration of profile. It seems that I need to merge these properties when used together, so I tried to add combine.children="append" and combine.self="append" to configuration of plugin, but it didn't help.

UPDATE: I've found the cause of this issue: I didn't mention that I have parent pom including from this one, and parent pom.xml has these lines:

      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <groupId>org.apache.maven.plugins</groupId>
        <version>3.0.0-M3</version>
        <configuration combine.children="append"> 
          <systemProperties>
            <!-- some properties that I don't use -->
          </systemProperties>
        </configuration>
      </plugin>

And these parent pom failsafe configuration is breaking all configs in my pom.xml - if I remove parent pom reference, failsafe properties will be included correctly. I can't just remove parent pom reference and can't modify it (actually I can fork it and edit, but it's not an easy task), is it possible to override these properties, since I don't use them?

Attached minimal reproducible project: https://send.firefox.com/download/88dfb9f933c9567f/#71ij1jbuEuAYgdwIiZQZRg

like image 444
Kirill Avatar asked Aug 18 '18 04:08

Kirill


1 Answers

I managed to do it by adding an extra pom in between the untouchable (or pariah) parent and current child, I call this new middle pom midboy =)

So midboy has only the following difference from pariah;

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <groupId>org.apache.maven.plugins</groupId>
    <version>3.0.0-M3</version>
    <inherited>false</inherited>
</plugin>

And this pom becomes the the new parent pom of the child, while it uses the original pariah pom as its parent.

child ---[inherits]---> midboy ---[inherits]---> pariah

With inherited:false I essentially cut-off the failsafe plugin being passed into the child and breaking its profile-based configuration addition to its own local failsafe plugin & config. & this works perfectly!

No skipping of the test this time! 😁

Running com.test.so51905256.PropITCase
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 s - in com.test.so51905256.PropITCase

p.s. don't forget to add some sort of <activation> for the test profile

like image 150
buræquete Avatar answered Dec 04 '22 14:12

buræquete