运行 Jenkins 构建会抛出:java.lang.reflect.InaccessibleObjectException

Dav*_*ham 5 java maven jenkins java-10

嘿,我正在尝试通过 Jenkins 构建运行 Maven Java 项目,它可以通过命令行完美运行,但是当我通过 Jenkins 运行它时。我收到此错误:

Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @425ea9cb
Run Code Online (Sandbox Code Playgroud)

这是完整的堆栈跟踪

Building remotely on Windows10 in workspace c:\jenkins\workspace\SELENIUM Single-Browser Automated Test
hudson.remoting.ProxyException: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @425ea9cb
    at java.lang.reflect.AccessibleObject.checkCanSetAccessible(Unknown Source)
    at java.lang.reflect.AccessibleObject.checkCanSetAccessible(Unknown Source)
    at java.lang.reflect.Field.checkCanSetAccessible(Unknown Source)
    at java.lang.reflect.Field.setAccessible(Unknown Source)
    at com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39)
    at com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)
Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from ip-172-20-68-132.eu-central-1.compute.internal/172.20.68.132:42200
        at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1741)
        at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
        at hudson.remoting.Channel.call(Channel.java:955)
        at hudson.FilePath.act(FilePath.java:1072)
        at hudson.FilePath.act(FilePath.java:1061)
        at org.jenkinsci.plugins.gitclient.Git.getClient(Git.java:144)
        at hudson.plugins.git.GitSCM.createClient(GitSCM.java:822)
        at hudson.plugins.git.GitSCM.createClient(GitSCM.java:813)
        at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
        at hudson.scm.SCM.checkout(SCM.java:504)
        at hudson.model.AbstractProject.checkout(AbstractProject.java:1208)
        at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:574)
        at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
        at hudson.model.Run.execute(Run.java:1810)
        at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
        at hudson.model.ResourceController.execute(ResourceController.java:97)
        at hudson.model.Executor.run(Executor.java:429)
Caused: hudson.remoting.ProxyException: java.lang.ExceptionInInitializerError
    at com.thoughtworks.xstream.XStream.setupConverters(XStream.java:811)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:496)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:465)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:411)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:378)
    at hudson.util.XStream2.<init>(XStream2.java:113)
    at hudson.ProxyConfiguration.<clinit>(ProxyConfiguration.java:308)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.sun.proxy.$Proxy10.<clinit>(Unknown Source)
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
    at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
    at hudson.remoting.RemoteInvocationHandler.wrap(RemoteInvocationHandler.java:167)
    at hudson.remoting.Channel.export(Channel.java:768)
    at hudson.remoting.Channel.export(Channel.java:731)
    at org.jenkinsci.plugins.gitclient.LegacyCompatibleGitAPIImpl.writeReplace(LegacyCompatibleGitAPIImpl.java:198)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at java.io.ObjectStreamClass.invokeWriteReplace(Unknown Source)
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at hudson.remoting.UserRequest._serialize(UserRequest.java:264)
    at hudson.remoting.UserRequest.serialize(UserRequest.java:273)
    at hudson.remoting.UserRequest.perform(UserRequest.java:223)
    at hudson.remoting.UserRequest.perform(UserRequest.java:54)
    at hudson.remoting.Request$2.run(Request.java:369)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:93)
    at java.lang.Thread.run(Unknown Source)
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)

Jenkins 甚至没有从存储库中检查代码,它位于 Windows 机器上,Java 版本是 10 任何人都可以帮忙吗?

rec*_*rom 7

以下帖子给出了该问题的一般概述,并讨论了使用--add-opensjava 命令行参数的解决方法:https ://stackoverflow.com/a/41265267/9457431

使用该命令行参数的多个实例使我能够避免问题中的异常以及 Jenkins 代理引发的类似异常。以下是我遇到的异常以及允许避免异常的相应参数。

例外情况:

hudson.remoting.ProxyException: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @2c07c27c
hudson.remoting.ProxyException: java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.reflect.InvocationHandler java.lang.reflect.Proxy.h accessible: module java.base does not "opens java.lang.reflect" to unnamed module @5f14797f
hudson.remoting.ProxyException: java.lang.reflect.InaccessibleObjectException: Unable to make protected java.lang.String java.text.AttributedCharacterIterator$Attribute.getName() accessible: module java.base does not "opens java.text" to unnamed module @1bd564bd
hudson.remoting.ProxyException: java.lang.reflect.InaccessibleObjectException: Unable to make field private static final java.util.Map java.awt.font.TextAttribute.instanceMap accessible: module java.desktop does not "opens java.awt.font" to unnamed module @e93c28
Run Code Online (Sandbox Code Playgroud)

命令行参数:

--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
--add-opens java.base/java.text=ALL-UNNAMED
--add-opens java.desktop/java.awt.font=ALL-UNNAMED
Run Code Online (Sandbox Code Playgroud)

这是代理启动命令:

java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED -jar agent.jar -jnlpUrl https://<Jenkins URL>/computer/<Node Identifier>/slave-agent.jnlp  -secret <Secret Value> -workDir "<Work Dir>"
Run Code Online (Sandbox Code Playgroud)

注意:我使用的是 openjdk 11 和 Jenkins 2.263.2