无法将属性从maven配置文件传递到maven failsafe插件

时间:2017-10-31 18:22:22

标签: java maven maven-plugin

我正在尝试根据配置文件执行集成测试。但是,我无法将属性传递给maven failsafe插件。请在下面找到我的POM

                http://maven.apache.org/xsd/maven-4.0.0.xsd">                   4.0.0                   com.comcast.iot                   账户服务                   0.0.1-SNAPSHOT                   罐                   2017年                   账户服务                   帐户服务

              <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>

使用此命令mvn verify -P integration-test,我得到System.getProperty(“build.profile.url”)的空值。但是,命令mvn verify -Dbuild.profile.url = http://localhost:8080 -P integration-test工作正常。请帮助我。感谢

1 个答案:

答案 0 :(得分:1)

如果您希望failafe插件使用系统属性(例如-Dbuild.profile.url=...)运行,那么您必须提供如下配置:

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

更多详情in the docs

通过这种方式,您已在配置文件中填充的Maven属性 - ${build.profile.url}将传播到由failsafe插件启动的任何JVM。

注意:您已经做了一些非常接近此事但您设置的是environmentVariables而不是systemPropertyVariables