jenkins使用sonarqube扫描代码报错:类似版本不兼容问题

jenkins使用sonarqube扫描代码报错:类似版本不兼容问题

报错日志

Branch indexing
git rev-parse --resolve-git-dir /var/jenkins_home/caches/git-e0b4b1039185df88e0effbc49732aa4b/.git # timeout=10
Setting origin to http://10.0.0.2:7080/root/prom-exporter.git
git config remote.origin.url http://10.0.0.2:7080/root/prom-exporter.git # timeout=10
Fetching origin…
Fetching upstream changes from origin
git --version # timeout=10
git --version # ‘git version 2.11.0’
git config --get remote.origin.url # timeout=10
using GIT_ASKPASS to set credentials 家里gitlab账号密码1
git fetch --tags --progress – origin +refs/heads/:refs/remotes/origin/ # timeout=10
Seen branch in repository origin/master
Seen 1 remote branch
Obtained Jenkinsfile from 2bfedd25770ee7b872f9500f3ad0cb56ea3e2552
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on home_centos in /home/jenkins_home/workspace/exporter_pipeline_master
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: NONE
using credential gitlabhome
Fetching changes from the remote Git repository
Fetching without tags
Checking out Revision 2bfedd25770ee7b872f9500f3ad0cb56ea3e2552 (master)
Commit message: “33344”
git rev-parse --resolve-git-dir /home/jenkins_home/workspace/exporter_pipeline_master/.git # timeout=10
git config remote.origin.url http://10.0.0.2:7080/root/prom-exporter.git # timeout=10
Fetching upstream changes from http://10.0.0.2:7080/root/prom-exporter.git
git --version # timeout=10
git --version # ‘git version 2.27.0’
using GIT_ASKPASS to set credentials 家里gitlab账号密码1
git fetch --no-tags --force --progress – http://10.0.0.2:7080/root/prom-exporter.git +refs/heads/:refs/remotes/origin/ # timeout=10
git config core.sparsecheckout # timeout=10
git checkout -f 2bfedd25770ee7b872f9500f3ad0cb56ea3e2552 # timeout=10
git rev-list --no-walk bd7c856788985d37b3141ad667cdc0d0de216874 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (代码扫描)
[Pipeline] sh
++ mvn sonar:sonar -Dsonar.projectKey=kang -Dsonar.host.url=http://10.0.0.2:9000 -Dsonar.login=8f5d17b176e826d6105c5497425a9ae2138b47e4
[INFO] Scanning for projects…
[WARNING]
[WARNING] Some problems were encountered while building the effective model for promethues:java-exporter:jar:1.0-SNAPSHOT
[WARNING] ‘build.plugins.plugin.version’ for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 20, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ----------------------< promethues:java-exporter >----------------------
[INFO] Building java-exporter 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] — sonar-maven-plugin:3.9.0.2155:sonar (default-cli) @ java-exporter —
[INFO] User cache: /root/.sonar/cache
[INFO] SonarQube version: 9.0.1
[INFO] Default locale: “zh_CN”, source code encoding: “UTF-8”
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.241 s
[INFO] Finished at: 2021-09-01T23:45:51+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar (default-cli) on project java-exporter: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.mojo:sonar-maven-plugin:3.9.0.2155
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/root/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.9.0.2155/sonar-maven-plugin-3.9.0.2155.jar
[ERROR] urls[1] = file:/root/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[2] = file:/root/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[3] = file:/root/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
[ERROR] urls[4] = file:/root/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.16.1.361/sonar-scanner-api-2.16.1.361.jar
[ERROR] urls[5] = file:/root/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------
[ERROR]
[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] PluginContainerException - Apache Maven - Apache Software Foundation
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (执行单侧)
Stage “执行单侧” skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (打包推送)
Stage “打包推送” skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (编译镜像)
Stage “编译镜像” skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (部署环境)
Stage “部署环境” skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] sh
++ echo 111
111
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

  • Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar (default-cli) on project java-exporter: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.0.2155:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
  • 不理解这句报错,我java版本是1.8,是插件版本问题吗?
  • 求助 该怎么解决?

sonar.host.url=http://10.0.0.2:9000
这个网你在传sonar的那个平台能访问通吗


把你项目的配置文件贴出来,或者扫描的项目的GitHub/gitee地址

访问的通的,是我本地局域网的。

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>promethues</groupId>
    <artifactId>java-exporter</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>4.0.6.RELEASE</spring.version>
        <allure.version>1.4.23</allure.version>
        <aspectj.version>1.8.5</aspectj.version>
    </properties>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.1</version>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                    <exclude>com.google.code.findbugs:jsr305</exclude>
                                    <exclude>org.slf4j:*</exclude>
                                    <exclude>log4j:*</exclude>
                                </excludes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <!-- Do not copy the signatures in the META-INF folder.
                                    Otherwise, this might cause SecurityExceptions when using the JAR. -->
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>exporter.CustomExporter</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <!-- The client -->
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient</artifactId>
            <version>0.6.0</version>
        </dependency>

        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_httpserver</artifactId>
            <version>0.6.0</version>
        </dependency>

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

        <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_pushgateway -->
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_pushgateway</artifactId>
            <version>0.10.0</version>
        </dependency>


        <dependency>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-testng-adaptor</artifactId>
            <version>${allure.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>


    <!-- 设置deploy的地址 -->
    <distributionManagement>
        <repository>
            <id>nexus-releases</id>                    <!--库的ID-->
            <name>Nexus Release Repository</name>   <!--库的名字-->
            <url>http://10.0.0.6:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>                    <!--库的ID-->
            <name>Nexus Snapshots Repository</name>   <!--库的名字-->
            <url>http://10.0.0.6:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>


</project>

你的sonarqube的平台是什么版本的?截图看下

看下官网,说的不要使用最新的,你的报错里面


换了各种版本插件,都还是报这个错

请问解决了吗