无法将属性从maven概要文件传递到maven failsafe插件

njthzxwz  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(295)

我正在尝试基于概要文件执行集成测试。但是,我无法将属性传递给maven failsafe插件。请在我的pom下面找到
http://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0 com.comcast.iot账户服务0.0.1-snapshot jar 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>

使用这个命令mvnverify-p integration test,我将获得system.getproperty的空值(“build.profile.url”)。但是,命令mvn verify-dbuild.profile.url=http://localhost:8080-p集成测试工作正常。请帮我解决这个问题。谢谢

esbemjvw

esbemjvw1#

如果您希望failsafe插件与系统属性一起运行(例如 -Dbuild.profile.url=... )然后必须提供如下配置:

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

更多细节见文件。
这样maven的财产- ${build.profile.url} -您已经在配置文件中填充的内容将被传播到failsafe插件启动的任何jvm。
注意:你已经做了一些非常接近这一点,但你正在设置 environmentVariables 而不是 systemPropertyVariables .

相关问题