我的 POM 有什么问题吗? “解析表达式..检测到递归表达式循环”

问题描述 投票:0回答:5

所以我有一些包含运行时参数的 TestNG SuiteXML 文件,如下所示:-

 <!--SERVER AND TARGET PARAMS-->
    <parameter name="environment" value="${environment}"/>
    <parameter name="port" value="${port}"/>

我的 POM 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>co.uk.multicom.test.project</groupId>
<artifactId>fab-handler-automation</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <sl4j.version>1.7.7</sl4j.version>
    <suiteFile>${suiteFile}</suiteFile>
    <environment>${environment}</environment>
    <port>${port}</port>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <systemProperties>
                    <property>
                        <name>javax.xml.parsers.SAXParserFactory</name>
                        <value>org.apache.xerces.jaxp.SAXParserFactoryImpl</value>
                    </property>
                    <property>
                        <name>user.language</name>
                        <value>en</value>
                    </property>
                </systemProperties>
                <!--<testFailureIgnore>true</testFailureIgnore>-->
                <suiteXmlFiles>
                    <suiteXmlFile>${suiteFile}</suiteXmlFile>
                </suiteXmlFiles>
                <systemPropertyVariables>
                    <environment>${environment}</environment>
                    <port>${port}</port>
                </systemPropertyVariables>
                <properties>
                    <property>
                        <name>parallel</name>
                        <value>methods</value>
                    </property>
                    <property>
                        <name>threadCount</name>
                        <value>1</value>
                    </property>
                    <property>
                        <name>dataproviderthreadcount</name>
                        <value>1</value>
                    </property>
                </properties>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <!-- https://mvnrepository.com/artifact/com.jayway.restassured/rest-assured -->
    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>2.9.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>4.4.6</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>htmlunit-driver</artifactId>
        <version>2.21</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.jexcelapi</groupId>
        <artifactId>jxl</artifactId>
        <version>2.6.12</version>
    </dependency>
    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.21</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <!-- pom.xml -->
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>3.0.0</version>
    </dependency>
</dependencies>

我的错误是:

[ERROR]     Resolving expression: '${environment}': Detected the following recursive expression cycle in 'environment': [environment] -> [Help 2]
[ERROR]     Resolving expression: '${port}': Detected the following recursive expression cycle in 'port': [port] -> [Help 2]

我是不是傻了?可能我毕竟只是一个测试人员,脑子很小。谁能帮我解决问题吗?我的 POM 看起来湿漉漉的吗?

在我可以修复它之前,它不会将我所需的 jar 下载到本地 .m2 - 我尝试过吹走 .m2 并执行 mvn install 等......没有喜悦。

java maven
5个回答
6
投票

你的错误来自这部分:

<properties>
    <sl4j.version>1.7.7</sl4j.version>
    <suiteFile>${suiteFile}</suiteFile>
    <environment>${environment}</environment>
    <port>${port}</port>
</properties>

当您使用 ${port} Maven 会在

<port>X</port>
中查找值,此处 X=${port} 等等...这就是为什么您会在这里遇到递归问题


3
投票

我不确定,因为我只有时间快速查看,但定义一个属性然后将该属性分配给自身是我认为您所做的事情,也是导致错误的原因。

你不能在你的pom中使用${suiteFile}而不在你的

<properties></properties>
中定义它吗?

或者你可以在pom中使用另一个属性名称吗? 例如:

 <properties>
        <suiteFile1>${suiteFile}</suiteFile>
        <environment1>${environment}</environment>
        <port1>${port}</port>
    </properties>

并在你的 pom 中进一步使用它们?


0
投票

也许你可以阅读maven文档,它会告诉我们不支持你写的格式。 https://maven.apache.org/pom.html#Properties

也许可以尝试以下方法:

<profiles>
    <profile>
        <id>test</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <os>
                <family>mac</family>
            </os>
        </activation>
        <properties>
             <suiteFile>${suiteFile}</suiteFile>
             <environment>${environment}</environment>
             <port>${port}</port>
        </properties>
   </profile>
</profiles>

并执行:

clean package -pl ${project_name} -am -Denv=prod -DskipTests=true

注意: ${project_name} 是您的项目名称

我描述可能有错误,你可以试试


0
投票

我在 pom.xml 的以下配置中遇到了同样的问题

 <properties>
       <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
   </properties>

....

<profiles>
    <profile>
        <id>envTestsXml</id>
        <properties>
            <suiteXmlFile>testngEnv.xml</suiteXmlFile>
        </properties>
    </profile>
    <profile>
        <id>pipelineTestsXml</id>
        <properties>
            <suiteXmlFile>testngPipeline.xml</suiteXmlFile>
        </properties>
    </profile>
</profiles>

......

<configuration>
  <suiteXmlFiles>
     <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
         </suiteXmlFiles
    </configuration>

我的目标是根据运行测试的环境动态选择所需的 testng.xml,maven 命令如下所示:

mvn test -PpipelineTestsXml -Duri=http://localhost:8000/api

mvn test -PenvTestsXml -Duri=https://some-url.com

即使我收到错误:解析表达式:'${suiteXmlFile}':在'suiteXmlFile'中检测到以下递归表达式循环:[suiteXmlFile] 测试仍然可以成功运行,但我同意 pom.xml 上出现此错误看起来不太好。

或者我尝试删除

<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>

来自属性部分,它仍然导致此错误 无法解析符号“suiteXmlFile”

一切都再次按预期进行。 我无法找出实现我的目标的方法,而且 pom.xml 文件没有错误,所以如果有人遇到同样的问题,请随时分享您是如何解决的。


-1
投票

我今天也遇到了同样的问题。更有趣的是,这是在我几分钟前成功执行同一个项目之后。事实证明,构建配置有错误,其中命令(清理包等)被写入配置文件中。
愚蠢的错误,但让我花了一些时间,而它早些时候工作的原因是因为我手动输入命令而不是使用保存的构建配置。

© www.soinside.com 2019 - 2024. All rights reserved.