将JDK更改为11

时间:2019-10-20 19:43:42

标签: java maven testng allure

我有一个使用Oracle JDK时创建的使用Maven + TestNG + Allure的测试项目:1.8 (java version "1.8.0_201"),运行测试和生成报告都很好。一段时间后,我尝试在使用更新的OpenJDK:11.0.4 (java version "11.0.4")的其他PC上设置该项目

我设法通过添加JAXB依赖项来修复正在运行的测试:

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.1</version>
    </dependency>

但是在尝试运行后尝试生成诱惑报告时仍然遇到问题 这是我得到的错误:

Generating report to temp directory...
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
        at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:139)
        at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:126)
        at io.qameta.allure.context.JacksonContext.<init>(JacksonContext.java:24)
        at io.qameta.allure.ConfigurationBuilder.useDefault(ConfigurationBuilder.java:50)
        at io.qameta.allure.Commands.createReportConfiguration(Commands.java:158)
        at io.qameta.allure.Commands.generate(Commands.java:63)
        at io.qameta.allure.Commands.serve(Commands.java:88)
        at io.qameta.allure.CommandLine.run(CommandLine.java:136)
        at java.base/java.util.Optional.orElseGet(Optional.java:369)
        at io.qameta.allure.CommandLine.main(CommandLine.java:72)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlElement
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 10 more
[ERROR] Can't generate allure report data

搜索它表明该问题仍然看起来像Java 11中已弃用的JAXB一样,是否有任何信息可以解决此问题?我认为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.edx.tests</groupId>
    <artifactId>FinalProject</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <browser>chrome</browser>
        <browser>firefox</browser>
        <aspectj.version>1.9.4</aspectj.version>
        <allure.version>2.9.0</allure.version>
        <allure.maven.plugin>2.9</allure.maven.plugin>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>${allure.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <systemPropertyVariables>
                        <browser>${browser}</browser>
                        <allure.results.directory>target/allure-results</allure.results.directory>
                        <allure.link.issue.pattern>https://example.org/issue/{}</allure.link.issue.pattern>
                        <allure.link.tms.pattern>https://example.org/tms/{}</allure.link.tms.pattern>
                    </systemPropertyVariables>
                    <argLine>
                        -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                    </argLine>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-maven</artifactId>
                <version>${allure.maven.plugin}</version>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <!--<excludeDefaults>true</excludeDefaults>-->
        <plugins>
            <plugin>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-maven</artifactId>
                <version>${allure.maven.plugin}</version>
                <configuration>
                    <reportVersion>2.4.1</reportVersion>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
</project>

在此还应更新哪些内容以解决该错误?

0 个答案:

没有答案