简体   繁体   中英

Not able to pass property from maven profile to maven failsafe plugin

I am trying to execute the integration test based on the profile. However, I am not able to pass the property to the maven failsafe plugin. Please find below my POM

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.comcast.iot account-service 0.0.1-SNAPSHOT jar 2017 account-service Account Service

              <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>1.5.6.RELEASE</version>
                <relativePath/>
                <!-- lookup parent from repository -->
              </parent>

              <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
                <java.version>1.8</java.version>
                <money.scala.version>2.11</money.scala.version>
                <money.version>0.9.0-RC2</money.version>
                <build.profile.url>http://localhost:8080</build.profile.url> 
              </properties>

              <profiles>
                <!-- The Configuration of the development profile -->
                <profile>
                  <id>dev</id>
                  <activation>
                    <activeByDefault>true</activeByDefault>
                  </activation>
                  <properties>
                    <build.profile.id>dev</build.profile.id>
                    <build.profile.url>http://localhost:8080</build.profile.url> 
                    <!--
                      Only unit tests are run when the development profile is active
                    -->
                    <skip.integration.tests>true</skip.integration.tests>
                    <skip.unit.tests>false</skip.unit.tests>
                  </properties>
                </profile>
                <!-- The Configuration of the integration-test profile -->
                <profile>
                  <id>integration-test</id>
                  <properties>
                    <build.profile.id>integration-test</build.profile.id>
                      <build.profile.url>https://account-ms-integration.g3.app.cloud.comcast.net</build.profile.url> 
                    <!--
                      Only integration tests are run when the integration-test profile is active
                    -->
                    <skip.integration.tests>false</skip.integration.tests>
                    <skip.unit.tests>true</skip.unit.tests>
                  </properties>
                </profile>
              </profiles>

              <repositories>
                <repository>
                  <id>mortar-releases</id>
                  <name>Comcast Public Repository</name>
                  <url>https://nexus.comcast.com/nexus/content/groups/public</url>
                  <releases>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                  </releases>
                  <snapshots>
                    <enabled>false</enabled>
                  </snapshots>
                </repository>
                <repository>
                  <id>mortar-snapshots</id>
                  <url>https://nexus.comcast.com/nexus/content/groups/public</url>
                  <releases>
                    <enabled>false</enabled>
                  </releases>
                  <snapshots>
                    <enabled>true</enabled>
                  </snapshots>
                </repository>
              </repositories>

              <distributionManagement>
                <repository>
                  <id>mortar-releases</id>
                  <url>https://nexus.comcast.com/nexus/content/repositories/releases/</url>
                </repository>
                <snapshotRepository>
                  <id>mortar-snapshots</id>
                  <url>https://nexus.comcast.com/nexus/content/repositories/snapshots/</url>
                </snapshotRepository>
              </distributionManagement>

                <dependencyManagement>
                  <dependencies>
                    <dependency>
                      <groupId>org.springframework.cloud</groupId>
                      <artifactId>spring-cloud-dependencies</artifactId>
                      <version>Dalston.SR4</version>
                      <type>pom</type>
                      <scope>import</scope>
                    </dependency>
                  </dependencies>
                </dependencyManagement>

              <dependencies>
                <dependency>
                  <groupId>com.comcast.iot</groupId>
                  <artifactId>dhx-common</artifactId>
                  <version>0.0.1-SNAPSHOT</version>
                </dependency>

                <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-actuator</artifactId>
                </dependency>
                <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-bus-amqp</artifactId>
                </dependency>
                <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-config</artifactId>
                </dependency>

                <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter</artifactId>
                </dependency>
                <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-test</artifactId>
                  <scope>test</scope>
                </dependency>
                <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
                <dependency>
                  <groupId>org.apache.commons</groupId>
                  <artifactId>commons-lang3</artifactId>
                  <version>3.6</version>
                </dependency>
                <dependency>
                  <groupId>javax.inject</groupId>
                  <artifactId>javax.inject</artifactId>
                  <version>1</version>
                </dependency>
                <dependency>
                  <groupId>com.fasterxml.jackson.datatype</groupId>
                  <artifactId>jackson-datatype-jsr310</artifactId>
                  <version>2.6.5</version>
                </dependency>
                <dependency>
                  <groupId>io.springfox</groupId>
                  <artifactId>springfox-swagger2</artifactId>
                  <version>2.6.1</version>
                </dependency>

                <!-- Redis -->
                <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-data-redis</artifactId>
                </dependency>
                <dependency>
                  <groupId>redis.clients</groupId>
                  <artifactId>jedis</artifactId>
                </dependency>
                <!-- Eureka -->
                <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-eureka</artifactId>
                </dependency>
              </dependencies>

              <build>
                <filters>
                  <filter>profiles/${build.profile.id}/config.properties</filter>
                </filters>
                <resources>
                  <resource>
                    <filtering>true</filtering>
                    <directory>src/main/resources</directory>
                  </resource>
                </resources>
                <plugins>
                  <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                  </plugin>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                      <source>${java.version}</source>
                      <target>${java.version}</target>
                      <encoding>${project.encoding}</encoding>
                    </configuration>
                  </plugin>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                      <execution>
                        <id>attach-sources</id>
                        <goals>
                          <goal>jar-no-fork</goal>
                        </goals>
                      </execution>
                    </executions>
                  </plugin>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.10.3</version>
                    <configuration>
                      <sourcepath>src/main/java/</sourcepath>
                      <show>public</show>
                      <failOnError>true</failOnError>
                    </configuration>
                    <executions>
                      <execution>
                        <id>attach-javadocs</id>
                        <goals>
                          <goal>jar</goal>
                        </goals>
                      </execution>
                    </executions>
                  </plugin>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.7</version>
                    <configuration>
                      <encoding>${project.encoding}</encoding>
                    </configuration>
                  </plugin>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.18.1</version>
                    <configuration>
                      <!-- Skips unit tests if the value of skip.unit.tests property is true -->
                      <skipTests>${skip.unit.tests}</skipTests>
                      <!-- Excludes integration tests when unit tests are run -->
                      <excludes>
                        <exclude>**/IT*.java</exclude>
                      </excludes>
                      <enableAssertions>true</enableAssertions>
                    </configuration>
                  </plugin>
                  <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.7.201606060606</version>
                    <configuration>
                      <rules>
                        <rule>
                          <element>CLASS</element>
                          <limits>
                            <limit>
                              <counter>LINE</counter>
                              <value>COVEREDRATIO</value>
                              <minimum>0.80</minimum>
                            </limit>
                            <limit>
                              <counter>BRANCH</counter>
                              <value>COVEREDRATIO</value>
                              <minimum>0.80</minimum>
                            </limit>
                            <limit>
                              <counter>INSTRUCTION</counter>
                              <value>COVEREDRATIO</value>
                              <minimum>0.80</minimum>
                            </limit>
                            <limit>
                              <counter>BRANCH</counter>
                              <value>COVEREDRATIO</value>
                              <minimum>0.80</minimum>
                            </limit>
                            <limit>
                              <counter>COMPLEXITY</counter>
                              <value>COVEREDRATIO</value>
                              <minimum>0.80</minimum>
                            </limit>
                            <limit>
                              <counter>METHOD</counter>
                              <value>COVEREDRATIO</value>
                              <minimum>0.80</minimum>
                            </limit>
                            <limit>
                              <counter>CLASS</counter>
                              <value>COVEREDRATIO</value>
                              <minimum>0.80</minimum>
                            </limit>
                          </limits>
                          <excludes>
                            <!-- <exclude>com.comcast.digitalhome.das.molecule.dao.MoleculeClientDaoImpl</exclude> -->
                          </excludes>
                        </rule>
                      </rules>
                    </configuration>
                    <executions>
                      <execution>
                        <goals>
                          <goal>prepare-agent</goal>
                        </goals>
                      </execution>
                      <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                          <goal>report</goal>
                          <!-- <goal>check</goal> -->
                        </goals>
                      </execution>
                    </executions>
                  </plugin>
                  <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.9.1</version>
                    <executions>
                      <execution>
                        <id>add-integration-test-sources</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                        <goal>add-test-source</goal>
                      </goals>
                      <configuration>
                        <sources>
                          <source>src/integration-test/java</source>
                        </sources>
                      </configuration>
                    </execution>
                    <!-- Add a new resource directory to our build -->
                    <execution>
                      <id>add-integration-test-resources</id>
                      <phase>generate-test-resources</phase>
                      <goals>
                        <goal>add-test-resource</goal>
                      </goals>
                      <configuration>
                        <resources>
                          <resource>
                            <filtering>true</filtering>
                            <directory>src/integration-test/resources</directory>
                          </resource>
                        </resources>
                      </configuration>
                    </execution>
                  </executions>
                  </plugin> 
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.18</version>
                    <executions>
                      <execution>
                             <id>integration-test</id>
                        <goals>
                          <goal>verify</goal>
                        </goals>
                        <configuration>
                         <environmentVariables>
                            <build.profile.url>${build.profile.url}</build.profile.url>
                         </environmentVariables>
                          <!--
                           Skips integration tests if the value of skip.integration.tests
                           property is true
                          -->
                          <skipTests>${skip.integration.tests}</skipTests>             
                        </configuration>
                      </execution>
                    </executions>
                  </plugin>
                </plugins>
              </build>
            </project>

with this command mvn verify -P integration-test, I am getting null value for System.getProperty("build.profile.url"). However, the command mvn verify -Dbuild.profile.url= http://localhost:8080 -P integration-test is working fine. Kindly help me on this. Thanks

If you want the failsafe plugin to run with a system property (such as -Dbuild.profile.url=... ) then you must supply a configuration like this:

    <configuration>
      <systemPropertyVariables>
        <build.profile.url>${build.profile.url}</build.profile.url>
      </systemPropertyVariables>
    </configuration>

More details in the docs .

In this way the Maven property - ${build.profile.url} - that you are already populating in your profile will be propagated to any JVM launched by the failsafe plugin.

Note : you are already doing something quite close to this but you are setting environmentVariables instead of systemPropertyVariables .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM