我正在使用Groovy编写Artifactory插件。 我需要它来获取Artifactory中所有存储库的列表。
在插件的lib文件夹中,我添加了jar:
artifactory-java-client-services-2.3.2.jar
Intellij知道要完成神器对象的方法:printscreen of the intellij
我试图在groovy文件中写这个:
import org.jfrog.artifactory.*
import org.jfrog.artifactory.client.*
....
....
def baseurl = <URL to the artifactory>
ArtifactoryClient artifactoryClient = new ArtifactoryClient();
def artifactory = artifactoryClient.create(baseurl, <the user name>, <the password>)
def allRepositories = artifactory.getRepositories()
但是当我将导入添加到文件时,Artifactory的控制台显示以下错误:
2017-05-04 09:42:04,468 [art-groovy-plugins-reloader] [ERROR] (o.a.a.p.GroovyRunnerImpl:302) - Error loading script from '..\etc\plugins\test.groovy'.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: java.lang.NoClassDefFoundError: Unable to load class org.jfrog.artifactory.client.ArtifactoryClient due to missing dependency org/jfrog/artifactory/client/Artifactory
java.lang.RuntimeException: java.lang.NoClassDefFoundError: Unable to load class org.jfrog.artifactory.client.ArtifactoryClient due to missing dependency org/jfrog/artifactory/client/Artifactory
at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1091)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1069)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.util.GroovyScriptEngine$ScriptClassLoader.doParseClass(GroovyScriptEngine.java:274)
at groovy.util.GroovyScriptEngine$ScriptClassLoader.parseClass(GroovyScriptEngine.java:243)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:212)
at groovy.util.GroovyScriptEngine.loadScriptByName(GroovyScriptEngine.java:555)
at org.artifactory.addon.plugin.GroovyRunnerImpl.loadScript(GroovyRunnerImpl.java:277)
at org.artifactory.addon.plugin.GroovyRunnerImpl.getScripts(GroovyRunnerImpl.java:257)
at org.artifactory.addon.plugin.GroovyRunnerImpl.reloadScripts(GroovyRunnerImpl.java:137)
at org.artifactory.addon.plugin.GroovyRunnerImpl$ScriptsReloader.run(GroovyRunnerImpl.java:451)
Caused by: java.lang.NoClassDefFoundError: Unable to load class org.jfrog.artifactory.client.ArtifactoryClient due to missing dependency org/jfrog/artifactory/client/Artifactory
at org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:391)
知道这里出了什么问题以及如何解决它?
答案 0 :(得分:0)
看起来您正在尝试开发Artifactory user plugin并在此插件中使用Artifactory client。虽然这是可行的,但它可能不是最好的方法 用户插件应使用Artifactory public API(PAPI)与Artifactory进行通信 对于您的用例,您应该使用Repositories类中提供的方法来获取可用存储库的列表。
Artifactory客户端实际上是在幕后使用Artifactory REST API,这可以从用户插件中使用,但比直接调用PAPI要慢。此外,客户端还需要指定您的Artifactory URL,这是您在编写插件时需要注意的另一个问题。
如果您确实想在用户插件中使用客户端,则应将相关的.jar文件(客户端和依赖项)放在plugins lib directory中。