Search code examples
javaeclipsemavencucumber

My tests were running and then I clicked "Run as --> Maven clean" and now when I click "Run as --> Maven test" it doesn't work anymore


My project worked after right-clicking on the pom.xml file in Eclipse and selecting: "Run as --> Maven install" and then "Run as --> Maven test".

I started experimenting around and selected: "Run as --> Maven clean" and then "Run as --> Maven install". This time around I got build errors and couldn't run "Run as --> Maven test". What happened? Why did I get build errors?

I can get the tests to work again if I exit out of Eclipse, delete everything in the .m2 folder, relaunch Eclipse, and click "Run as --> Maven install" twice (the first time produces an error, the second time does the trick). I have no clue as to why this works. I'm confused about what "Maven clean", "Maven install", and "Maven test" do. Yes, I've read the documentation on maven.apache.org but I'm still confused.

Here's 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>com.ah</groupId>
  <artifactId>goToLinks</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>GoToLinks</name>

    <dependencies>
        <!-- selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- cucumber-java -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>5.7.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>5.7.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
                    <parallel>methods</parallel>
                    <useUnlimitedThreads>true</useUnlimitedThreads>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Here's the error I'm getting:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.540 s
[INFO] Finished at: 2020-06-01T19:47:03-04:00
[INFO] ------------------------------------------------------------------------

Solution

  • The maven compiler plugin defaults to Java 1.5 but the version of the JDK you use no longer supports that. You can resolve that by configuring the compiler plugin to use a different version of java.

    https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

        <project>
          [...]
          <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
          </properties>
          [...]
        </project>
    

    or configure the plugin directly:

        <project>
          [...]
          <build>
            [...]
            <plugins>
              <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>
          [...]
        </project>