gpt4 book ai didi

java - SonarQube 5.6.1 在使用 Ant 编译 Java 7 项目时抛出错误的主要版本

转载 作者:行者123 更新时间:2023-11-29 04:42:13 26 4
gpt4 key购买 nike

我有一个使用 Ant 构建项目的 Jenkins 作业。

该项目使用 Java 7。Jenkins 作业的运行时也是 Java 7。我使用的是在 Java 8 上运行的 SonarQube 5.6.1。SonarQube 服务器运行良好。

但是,当在 Ant 中调用 <sonar:sonar /> 目标时,我收到以下错误,这显然是由于 Java 版本不匹配 (JVMCFRE003 bad major version)。我不确定如何解决这个问题。

sonar:
parsing buildfile jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml with URI = jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml from a zip file
parsing buildfile jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml with URI = jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml from a zip file
[available] Found: /var/lib/jenkins/slave/workspace/Build/Component/Build-subcomponent/builds/com.mycompany.myproj.bootstrap.site/compile
parsing buildfile jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml with URI = jar:file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar!/org/sonar/ant/antlib.xml from a zip file
[sonar:sonar] Apache Ant(TM) version 1.9.7 compiled on April 9 2016
[sonar:sonar] SonarQube Ant Task version: 2.2
[sonar:sonar] Loaded from: file:/opt/Ant_1.9.7/lib/sonar-ant-task-2.2.jar
[sonar:sonar] INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
[sonar:sonar] INFO: Work directory: /var/lib/jenkins/slave/workspace/Build/Component/Build-subcomponent/com.mycompany.myproj.bootstrap.site/../builds/com.mycompany.myproj.bootstrap.site/sonar
[sonar:sonar] INFO: SonarQube Server 5.6.1

BUILD FAILED
/var/lib/jenkins/slave/workspace/Build/Component/Build-subcomponent/build/common.xml:229: java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/sonar/api/utils/SonarException, offset=6
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:324)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:155)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:712)
at java.net.URLClassLoader.access$400(URLClassLoader.java:93)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:1164)
at java.security.AccessController.doPrivileged(AccessController.java:492)
at java.net.URLClassLoader.findClass(URLClassLoader.java:595)
at org.sonar.runner.impl.IsolatedClassloader.loadClass(IsolatedClassloader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:731)
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
at java.lang.J9VMInternals.prepare(J9VMInternals.java:514)
at java.lang.Class.getMethod(Class.java:1116)
at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:85)
at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
at java.security.AccessController.doPrivileged(AccessController.java:400)
at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
at org.sonar.runner.api.Runner.execute(Runner.java:100)
at org.sonar.ant.SonarTask.launchAnalysis(SonarTask.java:53)
at org.sonar.ant.SonarTask.execute(SonarTask.java:48)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:155)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.Main.runBuild(Main.java:854)
at org.apache.tools.ant.Main.startAnt(Main.java:236)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

最佳答案

问题是我们正在谈论 Jenkins 作业,作业中使用的 Java 版本将用于作业中的每个步骤。由于您使用 Java 7 运行该作业,因此分析也使用 Java 7 运行并且与 SonarQube 5.6+ 不兼容。

最简单的做法是将分析从 Ant 脚本转移到 SonarQube Scanner 构建步骤;它会让您选择与运行该作业的 Java 版本不同的 Java 版本。

或者你可以完成这个 with a pipeline

node() {
def jdk8 = tool 'jdk-8u45'
def jdk7 = tool 'jdk-7u70'
withEnv(["PATH+JDK7=${jdk7}/bin"]) {
sh 'ant [normal target here]'
}
withEnv(["PATH+JDK8=${jdk8}/bin"]) {
sh 'ant [analysis target here]'
}
}

您的第三个选择是将作业一分为二并使用共享工作区(配置 > 项目选项 > 高级 > 使用自定义工作区)

关于java - SonarQube 5.6.1 在使用 Ant 编译 Java 7 项目时抛出错误的主要版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38749172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com