Adding script to Nexus OSS

Hi,

I want to upload a script to a Nexus instance, to make it available via the script API. It is a more complicated, than a simple oneliner, so I tried to set up a Nexus 3 Groovy Script development environment based on this article:

When I try to upload the script to the instance via the command

groovy addUpdateScript.groovy -u admin -p admin -f nexus-script-example\src\main\groovy\allAssetLister.groovy -n test -h <nexus_url>

I get the below error. Any suggestions?

Thanks,
Balázs
groovy : WARNING: An illegal reflective access operation has occurred
At line:1 char:1

  • groovy addUpdateScript.groovy -u admin -p admin -f nexus-script-examp …
  •   + CategoryInfo          : NotSpecified: (WARNING: An ill...on has occurred:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/C:/Program%20Files/groovy-2.5.8/lib/groovy-2.5.8.jar) to constructor
java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing Grapes – [unresolved dependency: org.jboss.logging#jboss-logging-processor;2.0.1.Final: not found, unresolved dependency:
org.jboss.logging#jboss-logging-annotations;2.0.1.Final: not found, unresolved dependency: com.fasterxml.jackson.jaxrs#jackson-jaxrs-json-provider;2.8.6: not found, unresolved dependency:
com.fasterxml.jackson.core#jackson-annotations;2.8.6: not found, unresolved dependency: com.fasterxml.jackson.core#jackson-databind;2.8.6: not found, unresolved dependency:
com.fasterxml.jackson.core#jackson-core;2.8.6: not found, unresolved dependency: org.jboss.spec.javax.servlet#jboss-servlet-api_3.1_spec;1.0.0.Final: not found, unresolved dependency:
org.sonatype.nexus#nexus-rest-jackson2;3.9.0-01: not found, unresolved dependency: org.sonatype.nexus#nexus-rest-client;3.9.0-01: not found, download failed:
org.apache.james#apache-mime4j;0.6!apache-mime4j.jar, download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar, download failed:
com.sun.mail#javax.mail;1.5.6!javax.mail.jar, download failed: com.sun.xml.bind#jaxb-impl;2.2.7!jaxb-impl.jar, download failed: com.sun.xml.bind#jaxb-core;2.2.7!jaxb-core.jar, download
failed: javax.xml.bind#jaxb-api;2.2.7!jaxb-api.jar, download failed: com.sun.istack#istack-commons-runtime;2.16!istack-commons-runtime.jar, download failed:
com.sun.xml.fastinfoset#FastInfoset;1.2.12!FastInfoset.jar, download failed: javax.xml.bind#jsr173_api;1.0!jsr173_api.jar, download failed: javax.inject#javax.inject;1!javax.inject.jar,
download failed: aopalliance#aopalliance;1.0!aopalliance.jar]
java.lang.RuntimeException: Error grabbing Grapes – [unresolved dependency: org.jboss.logging#jboss-logging-processor;2.0.1.Final: not found, unresolved dependency:
org.jboss.logging#jboss-logging-annotations;2.0.1.Final: not found, unresolved dependency: com.fasterxml.jackson.jaxrs#jackson-jaxrs-json-provider;2.8.6: not found, unresolved dependency:
com.fasterxml.jackson.core#jackson-annotations;2.8.6: not found, unresolved dependency: com.fasterxml.jackson.core#jackson-databind;2.8.6: not found, unresolved dependency:
com.fasterxml.jackson.core#jackson-core;2.8.6: not found, unresolved dependency: org.jboss.spec.javax.servlet#jboss-servlet-api_3.1_spec;1.0.0.Final: not found, unresolved dependency:
org.sonatype.nexus#nexus-rest-jackson2;3.9.0-01: not found, unresolved dependency: org.sonatype.nexus#nexus-rest-client;3.9.0-01: not found, download failed:
org.apache.james#apache-mime4j;0.6!apache-mime4j.jar, download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar, download failed:
com.sun.mail#javax.mail;1.5.6!javax.mail.jar, download failed: com.sun.xml.bind#jaxb-impl;2.2.7!jaxb-impl.jar, download failed: com.sun.xml.bind#jaxb-core;2.2.7!jaxb-core.jar, download
failed: javax.xml.bind#jaxb-api;2.2.7!jaxb-api.jar, download failed: com.sun.istack#istack-commons-runtime;2.16!istack-commons-runtime.jar, download failed:
com.sun.xml.fastinfoset#FastInfoset;1.2.12!FastInfoset.jar, download failed: javax.xml.bind#jsr173_api;1.0!jsr173_api.jar, download failed: javax.inject#javax.inject;1!javax.inject.jar,
download failed: aopalliance#aopalliance;1.0!aopalliance.jar]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:80)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:74)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallC
onstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:237)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:249)
at groovy.grape.GrapeIvy.getDependencies(GrapeIvy.groovy:504)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:167)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:58)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)
at groovy.grape.GrapeIvy.resolve(GrapeIvy.groovy:693)
at groovy.grape.GrapeIvy.resolve(GrapeIvy.groovy:658)
at groovy.grape.GrapeIvy.grab(GrapeIvy.groovy:280)
at groovy.grape.Grape.grab(Grape.java:166)
at groovy.grape.GrabAnnotationTransformation.visit(GrabAnnotationTransformation.java:376)
at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:319)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:954)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:636)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:612)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:589)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:401)
at groovy.lang.GroovyClassLoader.access$300(GroovyClassLoader.java:89)
at groovy.lang.GroovyClassLoader$5.provide(GroovyClassLoader.java:341)
at groovy.lang.GroovyClassLoader$5.provide(GroovyClassLoader.java:338)
at org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:147)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:336)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:546)
at groovy.lang.GroovyShell.run(GroovyShell.java:375)
at groovy.lang.GroovyShell.run(GroovyShell.java:365)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:592)
at groovy.ui.GroovyMain.run(GroovyMain.java:336)
at groovy.ui.GroovyMain.access$1400(GroovyMain.java:69)
at groovy.ui.GroovyMain$GroovyCommand.process(GroovyMain.java:295)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:134)
at groovy.ui.GroovyMain.main(GroovyMain.java:116)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:110)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
1 error

Looks like the machine you’re running the addUpdateScript.groovy from either doesn’t have internet access, or there is something wrong with the groovy grapes configuration. Either way, the dependencies needed by that script can’t be downloaded.

Note that you don’t have to use the addUpdateScript.groovy, You can just use the REST API:

https://help.sonatype.com/repomanager3/rest-and-integration-api/script-api/managing-and-running-scripts

The REST API would be perfectly enough for me, but can I upload multiline scripts with it?

Absolutely. The following gist contains a few examples of single and multiline groovy scripts and a bash script which can upload them via the REST API.

The pertinent part is line L33 in the bash script

"content": "$(sed '/^$/d; /^\/\//d; s/"/\\"/g' ${script} | tr '\n' ';')",

which is taking the multiline script and performing the following transformations:

  • Removes empty lines
  • Removes line comments
  • Escapes double quotes \\"
  • Replaces newlines with semicolons