1

I have this pom structure and I am trying to access property hub.p, which is set in build-helper-maven-plugin, which is inside profile and stores port number . Port is assigned as I get on console something like this Reserved port 59831 for hub.p . I am unable to access this through resource filtering through another property hub.port , which is defined in properties section

<project xmlns="http://maven.apache.org/POM/4.0.0" 
...

<build>
 ....
           <resources>
                     <resource>
                            <directory>src/main/resources</directory>
                            <filtering>true</filtering>

                        </resource>
            </resources>  
  ...
</build>
        <properties>
        
             <hub.port>${hub.p}</hub.port>
        </properties>

       <dependencies>
        ...
      </dependencies>

  <profiles>
  
        <profile>
            <id>acceptanceTests</id>
        <build>
           ...
            <plugins>
             ....
            <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>build-helper-maven-plugin</artifactId>
               <executions>
                <execution>
                 <id>reserve-server-port</id>
                   <goals>
                   <goal>reserve-network-port</goal>
                  </goals>
                <phase>process-resources</phase>
                 <configuration>
                  <portNames>
                     <portName>hub.p</portName>
              </portNames>
            </configuration>
          </execution>
        </executions>
      </plugin>
     </plugins>
      ....
    </profile>
  </profiles>
</project 

in src/test/resources , I have pom.properties property file , which has this

hubPort=${hub.port}

And I am accessing property like this

            Properties properties = new Properties();
            
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            InputStream inputStream = loader.getResourceAsStream("pom.properties"); 
            properties.load(inputStream);
            String portForHub = properties.getProperty("hubPort");
            System.out.println("hubport..."+portForHub);

But it prints

hubport...${hub.port}

I referred to this question ,but I am not able to access the property.

user1207289
  • 3,060
  • 6
  • 30
  • 66

1 Answers1

0

The below worked for me. Instead of resource filtering, I passed ${hub.p} directly to <systemPropertyVariables> of failsafe plugin, so it can be captured in tests.

In failsafe plugin config

                 <configuration>
                    <parallel>methods</parallel>
                     <threadCount>4</threadCount>
                    <useUnlimitedThreads>true</useUnlimitedThreads>
                       <systemPropertyVariables>
                            <hub.port>${hub.p}</hub.port>                         
                      </systemPropertyVariables>
                  </configuration>

And then in tests

System.getProperty("hub.port")

This question helped

user1207289
  • 3,060
  • 6
  • 30
  • 66