java - 使用“mvn test”从命令行运行会在找不到依赖项 jar 时出现错误
问题描述
我有两个项目。AutomationFramework 只是库/公共页面/基类等。我从中创建了一个 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 clean和mvn compile)。另外,我注意到它在上面寻找 .java 源文件。“mvn verify”也给出了上述错误。
通过 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,<dependency>
您的FBRAutomationTestSuite
项目中没有引用AutomationResourcesFramework
工件,例如:
<dependency>
<groupId>com.agricorp</groupId>
<artifactId>automation-resources-framework</artifactId>
<version>...</version>
</dependency>
推荐阅读
- python - Python List 分配似乎被带走了
- django - sites_query = connection.execute("SELECT domain FROM django_site") psycopg2 没有属性执行
- javascript - 如何捕捉“JavaScript 堆内存不足”?
- java - java.lang.UnsupportedOperationException:反射 setAccessible(true) 已禁用
- c# - 不必要的 NullReferenceException?
- javascript - 如何在javascript中为蛇添加头部
- javascript - 更新后如何重新渲染 Formik 值 - React Native?
- github - 我可以将其他 git 存储库导入到我的存储库吗?
- ios - 我们如何使用 swiftUI 获取数据并像 viewdidload 一样显示
- python - 在 Pandas 中按数据类型处理数据