簡體   English   中英

使用“mvn test”從命令行運行會給出錯誤,其中找不到依賴項 jar

[英]Running from command line using "mvn test" gives error where dependency jar is not found

我有兩個項目。 AutomationFramework 只是庫/公共頁面/基礎 class 等。我從中創建了一個 jar 並添加到主要測試項目,即自動化測試套件。 我可以從 Eclipse (2021-06) 成功運行所有 7 個測試。 我喜歡從命令行運行它們,然后將其設置為從 Jenkins 運行。當鍵入“ mvn test ”時出現此錯誤:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[6,54] package com.agricorp.AutomationResourcesFramework.Base does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[7,57] package com.agricorp.AutomationResourcesFramework.Globals does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[8,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[9,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/SelectAccrditedFarmOrganizationPage.java:[11,58] cannot find symbol
  symbol: class Base
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[10,54] package com.agricorp.AutomationResourcesFramework.Base does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[11,57] package com.agricorp.AutomationResourcesFramework.Globals does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[12,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[13,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[14,57] package com.agricorp.AutomationResourcesFramework.Helpers does not exist
[ERROR] /C:/TFS/TS JAVA Automation/Development/FBRAutomationTestSuite/src/test/java/com/agricorp/FBRAutomationTestSuite/Pages/ReviewFarmBusinessInformationPage.java:[16,56] cannot find symbol
  symbol: class BasePageSetup

錯誤信息

順便說一句,我已經從命令行成功清理和編譯(使用mvn cleanmvn compile )。 另外,我注意到它正在尋找上面的 .java 源文件。 “mvn verify”也給出了上述錯誤。

通過 Eclipse 中的項目設置”

Eclipse項目結構

      <name>AutomationResourcesFramework</name>
      <!-- FIXME change it to the project's website -->
      <url>http://www.example.com</url>

      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
      </properties>

      <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency> 
        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.8.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.14.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.14.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.4.0</version>
            <!--scope>test</scope-->
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>5.0.8</version>
        </dependency>           
        <!-- https://mvnrepository.com/artifact/com.codoid.products/fillo -->
        <dependency>
            <groupId>com.codoid.products</groupId>
            <artifactId>fillo</artifactId>
            <version>1.21</version>
        </dependency>
      </dependencies>

        <profiles>
            <profile>
                <id>SanityTests</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>3.0.0-M5</version>
                            <configuration>
                                <suiteXmlFiles>
                                    <suiteXmlFile>testng.xml</suiteXmlFile>
                                </suiteXmlFiles>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <profile>
                <id>RegressionTests</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>3.0.0-M5</version>
                            <configuration>
                                <suiteXmlFiles>
                                    <suiteXmlFile>FBRAutomationTestSuite.xml</suiteXmlFile>
                                </suiteXmlFiles>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>

      <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
          <plugins>
            <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
            <plugin>
              <artifactId>maven-clean-plugin</artifactId>
              <version>3.1.0</version>
            </plugin>
            <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
            <plugin>
              <artifactId>maven-resources-plugin</artifactId>
              <version>3.0.2</version>
            </plugin>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.8.0</version>
            </plugin>
            <plugin>
              <artifactId>maven-jar-plugin</artifactId>
              <version>3.0.2</version>
            </plugin>
            <plugin>
              <artifactId>maven-install-plugin</artifactId>
              <version>2.5.2</version>
            </plugin>
            <plugin>
              <artifactId>maven-deploy-plugin</artifactId>
              <version>2.8.2</version>
            </plugin>
            <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
            <plugin>
              <artifactId>maven-site-plugin</artifactId>
              <version>3.7.1</version>
            </plugin>
            <plugin>
              <artifactId>maven-project-info-reports-plugin</artifactId>
              <version>3.0.0</version>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </project>

AFAICS,您的FBRAutomationTestSuite項目中沒有<dependency>引用AutomationResourcesFramework工件,例如:

        <dependency>
            <groupId>com.agricorp</groupId>
            <artifactId>automation-resources-framework</artifactId>
            <version>...</version>
        </dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM