【问题标题】:Issue with maven compilemaven编译问题
【发布时间】:2020-07-16 05:35:04
【问题描述】:

在 jenkins 中尝试使用 selenium wd 和 testng 构建 E2E 项目时,出现以下错误:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[9,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[10,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[11,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[12,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[13,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[14,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[15,22] package org.testng.xml does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[21,42] cannot find symbol
  symbol: class IReporter
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[24,37] cannot find symbol
  symbol:   class XmlSuite
  location: class resources.ExtentReporterNG
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[24,63] cannot find symbol
  symbol:   class ISuite
  location: class resources.ExtentReporterNG
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[43,33] cannot find symbol
  symbol:   class IResultMap
  location: class resources.ExtentReporterNG
[INFO] 11 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.605 s
[INFO] Finished at: 2020-04-03T19:51:37-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project E2EProject: Compilation failure: Compilation failure: 
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[9,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[10,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[11,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[12,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[13,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[14,18] package org.testng does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[15,22] package org.testng.xml does not exist
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[21,42] cannot find symbol
[ERROR]   symbol: class IReporter
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[24,37] cannot find symbol
[ERROR]   symbol:   class XmlSuite
[ERROR]   location: class resources.ExtentReporterNG
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[24,63] cannot find symbol
[ERROR]   symbol:   class ISuite
[ERROR]   location: class resources.ExtentReporterNG
[ERROR] /Users/VickoS/.jenkins/E2EProject/src/main/java/resources/ExtentReporterNG.java:[43,33] cannot find symbol
[ERROR]   symbol:   class IResultMap
[ERROR]   location: class resources.ExtentReporterNG
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

之前运行 mvn compile 命令时没有发生这种情况,但是在更新我的 POM 并重新编译后,它也开始显示在终端中。从 Eclipse 中的 testng.xml 运行项目时,该项目运行良好。

这是我的 POM 文件的样子

 <url>http://maven.apache.org</url>



  <build>
   <resources>
        <resource>
            <directory>src/main/java/resources</directory>
            <filtering>true</filtering> 
        </resource>
    </resources>
  <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M4</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
          <configuration>
             <source>1.8</source>
             <target>1.8</target>
          </configuration>
       </plugin>
</plugins>


  </build>
  <dependencies>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.apple</groupId>
      <artifactId>AppleJavaExtensions</artifactId>
      <version>1.4</version>
    </dependency>

       <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.4.0</version>
    </dependency>  

    <dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>7.1.0</version>
  <scope>test</scope>
</dependency>

  <dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.0.6</version>
</dependency>

 <dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>

      <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.8.2</version>
  </dependency>

  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8.2</version>
  </dependency>

  </dependencies>
</project>

附上项目外观的图片:

Project

【问题讨论】:

  • 从 pom 文件中的 testng 依赖项中删除 test。保存pom文件,然后编译,应该可以了。
  • 删除配置src/main/java/resources 因为它违反了配置范例的约定。此外,您应该默认在src/main/resources 中找到资源...并首先清除编译错误..
  • 如果你想使用 testng 做一些可以看到依赖的类需要进入 src/test/java - 所以将 ExtentReporterNG.java 移动到该文件夹​​结构 - 路径 /src/main /java/resources/ 看起来很奇怪。 “资源”是你的包名吗?还是有什么东西不小心移动了?
  • 从范围中删除“测试”不起作用。是的,资源是包名
  • @Vicko 如果resources 是包名称(可能是个坏主意),但您不应该在包中添加资源过滤,只有*.java 应该位于...资源(属性文件等)应位于src/main/resources ...

标签: java maven jenkins testng pom.xml


【解决方案1】:

我终于能够通过更新我的 POM 文件执行以下操作来解决这个问题: 删除具有 avenstack groupID 的范围报告依赖项

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.0.6</version>
</dependency>

将其他范围报告更新为此 v:

<dependency>
     <groupId>com.aventstack</groupId>
     <artifactId>extentreports</artifactId>
     <version>3.1.5</version>
  </dependency>

并添加这个:

<dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>2.3.28</version>
    </dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 2015-01-12
    • 2013-11-29
    • 2018-04-03
    • 2021-10-04
    相关资源
    最近更新 更多