【问题标题】:Intellij compile error: java: error: release version 5 not supportedIntellij 编译错误:java:错误:不支持发布版本 5
【发布时间】:2021-03-08 15:36:04
【问题描述】:

我有以下 pom.xml 文件,它没有编译和运行测试 (selenium)。我正在使用 Maven。

我有 java 版本 15,但由于我在这里看到的一些答案而将设置设置为 11。这会是个问题吗?

<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.in28minutes</groupId>
    <artifactId>web-driver-3-cross-browser-framework</artifactId>
    <version>0.0.1-SNAPSHOT</version>



    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <release>11</release>  <!--or <release>10</release>-->
            </configuration>
        </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.13.0</version>
            <scope>test</scope>
        </dependency>

        <!-- https://github.com/bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>2.2.4</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.13</version>
            <scope>test</scope>
        </dependency>

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

        <!-- https://mvnrepository.com/artifact/com.codeborne/phantomjsdriver -->
        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.4.4</version>
            <scope>test</scope>
        </dependency>


    </dependencies>
</project>

我不知道还能写什么,请告诉我如何帮助您回答我的问题。

【问题讨论】:

  • 使用基于完整文本的错误堆栈跟踪更新问题
  • 为什么将 Maven 编译器设置为 1.8,将发行版设置为 11? Maven 编译器设置也应该是 11 吗?

标签: java selenium maven pom.xml


【解决方案1】:

感谢大家的回答,我的问题已经通过本网站的方法#1解决了。

https://dev.to/techgirl1908/intellij-error-java-release-version-5-not-supported-376

【讨论】:

  • 我的是用同一个网站的方法解决的,但我不得不使用方法#1和#3。
【解决方案2】:

我刚刚复制了你的 pom 并修改了一些工件,如下所示,

<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>Sample-Mvn</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <release>11</release>  <!--or <release>10</release>-->
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.7.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.141.5</version>
        </dependency>

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>4.2.2</version>
            <scope>test</scope>
        </dependency>

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

    </dependencies>
</project>

测试类,它对我来说很好用。确保您的系统中安装了geckodriver

public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver();
        WebDriverWait wait = new WebDriverWait(driver, 10L);
        try {
            driver.get("https://google.com/ncr");
            driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER);
            WebElement firstResult = wait.until(presenceOfElementLocated(By.cssSelector("h3>div")));
            System.out.println(firstResult.getAttribute("textContent"));
        } finally {
            driver.quit();
        }

    }

【讨论】:

  • 嗨@Thangavel Loganathan,使用您的 pom.xml 配置文件后,我仍然收到错误消息
猜你喜欢
  • 2020-04-23
  • 1970-01-01
  • 2021-05-09
  • 2022-01-24
  • 1970-01-01
  • 1970-01-01
  • 2019-03-18
  • 2019-01-08
相关资源
最近更新 更多