Home > Mobile >  Intellij mvn install complains "cannot access <package>" during testComplile after a
Intellij mvn install complains "cannot access <package>" during testComplile after a

Time:10-29

I am planning to use Cucumber Test with Junit 5 in Maven. So I followed enter image description here It seems like the compiler can't read the package name? Below is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>onetwothree</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

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

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <build>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>11</source>
          <target>11</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
          <properties>
            <configurationParameters>
              cucumber.junit-platform.naming-strategy=long
            </configurationParameters>
          </properties>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>5.9.0</version>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>7.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-junit-platform-engine</artifactId>
      <version>7.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-suite</artifactId>
      <version>1.9.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

My project structure is:

enter image description here

but if I comment out cucumber-junit-platform-engine dependency in pom.xml, the error is gone but it won't run the cucumber tests. Did I miss something here?

Not sure if it's related, but one of the error messages is like:

[ERROR] error reading /Users/xx/.m2/repository/org/junit/platform/junit-platform-engine/1.9.1/junit-platform-engine-1.9.1.jar; zip file is empty
[ERROR] /Users/xx/Desktop/zz/src/test/java/pirate/Runner.java:[1,1] cannot access pirate
  ZipException opening "junit-platform-engine-1.9.1.jar": zip END header not found

CodePudding user response:

did you tried with a different scope than test for the cucumber-junit-platform-engine dependency?

CodePudding user response:

Maven : error in opening zip file when running maven

following the procedure fixes the "cannot access " problem.

  • Related