jfrog / artifactory-client-java

Artifactory REST Client Java API bindings
Apache License 2.0
319 stars 153 forks source link

Unable to import/use artifactory java client in an artifactory groovy plugin #278

Open ajinkyasurya opened 4 years ago

ajinkyasurya commented 4 years ago

Trying to import artifactory java client in an artifactory groovy plugin. Groovy Script to reproduce -

import java.util.Date

import org.jfrog.artifactory.client.Artifactory
import org.jfrog.artifactory.client.ArtifactoryClientBuilder

executions {
    reproduce(httpMethod: "GET") { params ->
        Artifactory artifactory = ArtifactoryClientBuilder.create()
                .setUrl("https://" + System.getenv("ARTIFACTORY_BASE_DOMAIN_NAME") + "/artifactory")
                .setUsername("USER")
                .setPassword("PASSWORD")
                .build()
        String filePath = "artifactory-plugins/plugin/" + System.getenv("ARTIFACTORY_BASE_DOMAIN_NAME") + "-" + new Date().getTime() + ".json"
        org.jfrog.artifactory.client.model.File result = artifactory.repository("master").upload(filePath, file).doUpload()
        message = "Invoked plugin successfully. Link - " + result.getDownloadUri()
        status = 200
    }
}

When I invoke the plugin, it throws following exception -

java.lang.NoClassDefFoundError: org/jfrog/artifactory/client/impl/util/ArtifactoryHttpClient
    org.jfrog.artifactory.client.ArtifactoryClientBuilder.createClientBuilder(ArtifactoryClientBuilder.java:115)
    org.jfrog.artifactory.client.ArtifactoryClientBuilder.build(ArtifactoryClientBuilder.java:167)
    org.jfrog.artifactory.client.ArtifactoryClientBuilder$build$3.call(Unknown Source)
    org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
    reproduce-bug$_run_closure1$_closure2.doCall(reproduce-bug.groovy:9)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)
    groovy.lang.Closure.call(Closure.java:426)
    groovy.lang.Closure.call(Closure.java:442)
    org.artifactory.addon.plugin.execution.ExecutePluginImpl.execute(ExecutePluginImpl.java:104)
    org.artifactory.addon.plugin.ScriptDelegate.execute(ScriptDelegate.java:85)
    org.artifactory.addon.plugin.GroovyRunnerImpl.execute(GroovyRunnerImpl.java:107)
    sun.reflect.GeneratedMethodAccessor283.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)
    com.sun.proxy.$Proxy137.execute(Unknown Source)
    org.artifactory.addon.plugin.PluginsAddonImpl.execute(PluginsAddonImpl.java:55)
    org.artifactory.addon.rest.RestAddonImpl.runPluginExecution(RestAddonImpl.java:1267)
    sun.reflect.GeneratedMethodAccessor282.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)
    com.sun.proxy.$Proxy152.runPluginExecution(Unknown Source)
    org.artifactory.rest.resource.plugin.PluginsResource.execute(PluginsResource.java:136)
    sun.reflect.GeneratedMethodAccessor281.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.artifactory.webapp.servlet.RepoFilter.execute(RepoFilter.java:200)
    org.artifactory.webapp.servlet.RepoFilter.doFilter(RepoFilter.java:91)
    org.artifactory.webapp.servlet.AccessFilter.useAuthentication(AccessFilter.java:391)
    org.artifactory.webapp.servlet.AccessFilter.authenticateAndExecute(AccessFilter.java:270)
    org.artifactory.webapp.servlet.AccessFilter.doFilterInternal(AccessFilter.java:200)
    org.artifactory.webapp.servlet.AccessFilter.doFilter(AccessFilter.java:160)
    org.artifactory.webapp.servlet.RequestFilter.doFilter(RequestFilter.java:61)
    org.artifactory.webapp.servlet.ArtifactoryFilter.doFilter(ArtifactoryFilter.java:111)

I tried with several artifactory-java-client-services-*.jar with no luck.

I'm currently on Artifactory 4.x. I also import the jar in lib folder as specified in the jfrog docs. It does work for couple of other external libraries as well but not Artifactory Java client.

julien-deruere commented 3 years ago

Any solutions? I have the same problem