通过 Jenkins 运行 Maven 项目(Git 存储库)时出现编译错误
Compilation Error while Running Maven Project(Git Repository) through Jenkins
我在 Jenkins 中设置了一个 Maven 项目。我已经对代码进行了更新,提交并将其推送到远程(Git 存储库)。我将 jenkins 配置为 maven 目标作为测试,然后单击构建,然后在 Jenkins 中编译 类 时出现错误。据我所知,Maven 只对 类 路径下存在的 类 进行测试。当我通过 Jenkins 构建项目时,出现以下编译错误,
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ myTestMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\s\.jenkins\workspace\meven_jenkin_sele\myTestMaven\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/s/.jenkins/workspace/meven_jenkin_sele/myTestMaven/src/main/java/com/testingMeven/myTestMaven/App.java:[3,30] package org.testng.annotations does not exist
[ERROR] /C:/Users/s/.jenkins/workspace/meven_jenkin_sele/myTestMaven/src/main/java/com/testingMeven/myTestMaven/App.java:[16,6] cannot find symbol
symbol: class Test
location: class com.testingMeven.myTestMaven.App
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
我的 git 回购 link https://github.com/SACTAN/myTestMaven
我尝试为 App.java 添加注释,但仍然出现同样的错误。当我 运行 在本地使用相同的代码时,它工作正常但无法通过 Jenkins 工作。有什么想法可能会出错吗?
您不能在 src/main
中使用范围为 test
的依赖项。如果您想在主代码中使用 TestNG,那么您可以从 POM 中的 TestNG dependency
中删除 <scope>test</scope>
。
这适用于任何 Maven 依赖项,而不仅仅是 TestNG。阅读 Dependency Scope 以了解更多信息。
我在 Jenkins 中设置了一个 Maven 项目。我已经对代码进行了更新,提交并将其推送到远程(Git 存储库)。我将 jenkins 配置为 maven 目标作为测试,然后单击构建,然后在 Jenkins 中编译 类 时出现错误。据我所知,Maven 只对 类 路径下存在的 类 进行测试。当我通过 Jenkins 构建项目时,出现以下编译错误,
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ myTestMaven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\s\.jenkins\workspace\meven_jenkin_sele\myTestMaven\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/s/.jenkins/workspace/meven_jenkin_sele/myTestMaven/src/main/java/com/testingMeven/myTestMaven/App.java:[3,30] package org.testng.annotations does not exist
[ERROR] /C:/Users/s/.jenkins/workspace/meven_jenkin_sele/myTestMaven/src/main/java/com/testingMeven/myTestMaven/App.java:[16,6] cannot find symbol
symbol: class Test
location: class com.testingMeven.myTestMaven.App
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
我的 git 回购 link https://github.com/SACTAN/myTestMaven
我尝试为 App.java 添加注释,但仍然出现同样的错误。当我 运行 在本地使用相同的代码时,它工作正常但无法通过 Jenkins 工作。有什么想法可能会出错吗?
您不能在 src/main
中使用范围为 test
的依赖项。如果您想在主代码中使用 TestNG,那么您可以从 POM 中的 TestNG dependency
中删除 <scope>test</scope>
。
这适用于任何 Maven 依赖项,而不仅仅是 TestNG。阅读 Dependency Scope 以了解更多信息。