Jenkins 共享库无法将 Java 类从 src 导入到 vars 脚本

问题描述

我创建了具有以下结构的共享 jenkins 库:

  • mylib/src/com/company/config/Config.java(这个类包含 lambdas)
  • mylib/vars/configClient.groovy(包含多个带有@Noncps 注释的方法并从 com.company.config.Config 导入)

此共享库通过@Library('mylib@develop') 作为基于文件夹的共享库包含在 Jenkins 上 我在 configClient.groovy 中得到结果异常:org.jenkinsci.plugins.workflow.cps.cpsCompilationErrorsException: startup Failed: .... unable to resolve class

我多次验证了打包路径(这是正确的),我将包结构从 Maven 修改为 src/ - vars/。我用@Noncps 注释了groovy 脚本中的所有函数,因为java 类非常复杂,无法序列化。我还通过 new 创建了简单的类,但我得到了同样的错误:'无法解析类'

public class SimpleObjToTest {

    public void lol() {
        System.out.println("LOLOLO");
    }
}

Detailed stacktrace looks like this:
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.compilationunit.applyToSourceUnits(compilationunit.java:958)
    at org.codehaus.groovy.control.compilationunit.doPhaSEOperation(compilationunit.java:605)
    at org.codehaus.groovy.control.compilationunit.compile(compilationunit.java:554)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
    at groovy.lang.GroovyClassLoader.recompile(GroovyClassLoader.java:761)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:718)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
    at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
    at org.jenkinsci.plugins.workflow.cps.global.UserDefinedGlobalVariable.getValue(UserDefinedGlobalVariable.java:57)
    at org.jenkinsci.plugins.workflow.cps.cpsScript.getProperty(cpsScript.java:135)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
    at org.kohsuke.groovy.sandBox.impl.Checker$7.call(Checker.java:355)
    at org.kohsuke.groovy.sandBox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
    at org.jenkinsci.plugins.scriptsecurity.sandBox.groovy.SandBoxInterceptor.onGetProperty(SandBoxInterceptor.java:354)
    at org.kohsuke.groovy.sandBox.impl.Checker$7.call(Checker.java:353)
    at org.kohsuke.groovy.sandBox.impl.Checker.checkedGetProperty(Checker.java:357)
    at org.kohsuke.groovy.sandBox.impl.Checker.checkedGetProperty(Checker.java:333)
    at org.kohsuke.groovy.sandBox.impl.Checker.checkedGetProperty(Checker.java:333)
    at org.kohsuke.groovy.sandBox.impl.Checker.checkedGetProperty(Checker.java:333)
    at org.kohsuke.groovy.sandBox.impl.Checker.checkedGetProperty(Checker.java:333)
    at org.kohsuke.groovy.sandBox.impl.Checker.checkedGetProperty(Checker.java:333)
    at org.kohsuke.groovy.sandBox.impl.Checker.checkedGetProperty(Checker.java:333)
    at org.kohsuke.groovy.sandBox.impl.Checker.checkedGetProperty(Checker.java:333)
    at com.cloudbees.groovy.cps.sandBox.SandBoxInvoker.getProperty(SandBoxInvoker.java:29)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at WorkflowScript.run(WorkflowScript:195)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
    at sun.reflect.GeneratedMethodAccessor234.invoke(UnkNown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandBoxContinuable.access$001(SandBoxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandBoxContinuable.run0(SandBoxContinuable.java:51)
    at org.jenkinsci.plugins.workflow.cps.cpsThread.runNextChunk(cpsThread.java:185)
    at org.jenkinsci.plugins.workflow.cps.cpsThreadGroup.run(cpsThreadGroup.java:400)
    at org.jenkinsci.plugins.workflow.cps.cpsThreadGroup.access$400(cpsThreadGroup.java:96)
    at org.jenkinsci.plugins.workflow.cps.cpsThreadGroup$2.call(cpsThreadGroup.java:312)
    at org.jenkinsci.plugins.workflow.cps.cpsThreadGroup$2.call(cpsThreadGroup.java:276)
    at org.jenkinsci.plugins.workflow.cps.cpsVmExecutorService$2.call(cpsVmExecutorService.java:67)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:136)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

我从管道中调用了这个库。有人可以提出任何关于如何调试或修复的想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...