# Adding script to Nexus OSS

**URL:** <https://community.sonatype.com/t/adding-script-to-nexus-oss/3257>\
**Category:** Sonatype Nexus Repository\
**Created:** [January 9, 2020, 1:59pm UTC](https://community.sonatype.com/t/adding-script-to-nexus-oss/3257 "2020-01-09T13:59:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![balazs.bayer](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@balazs.bayer](https://community.sonatype.com/u/balazs.bayer)\
**Post date:** [January 9, 2020, 1:59pm UTC](https://community.sonatype.com/t/adding-script-to-nexus-oss/3257/1 "2020-01-09T13:59:07Z")

</div>

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:

> **[Nexus Repository 3 Groovy Script development environment setup](https://support.sonatype.com/hc/en-us/articles/115015812727-Nexus-Repository-3-Groovy-Script-development-environment-setup)**
>
>  
> Note: Groovy scripting is disabled by default for security reasons. Development work on the groovy API was halted, and it will eventually be fully deprecated.  Groovy scripting can also cause per...

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 …
- 

```auto
  + 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

---

<div class="post-metadata">

**Author:** ![rseddon](https://yyz1.discourse-cdn.com/flex047/user_avatar/community.sonatype.com/rseddon/32/341_2.png) [@rseddon](https://community.sonatype.com/u/rseddon)\
**Post date:** [January 9, 2020, 4:12pm UTC](https://community.sonatype.com/t/adding-script-to-nexus-oss/3257/2 "2020-01-09T16:12:21Z")

</div>

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](https://help.sonatype.com/repomanager3/rest-and-integration-api/script-api/managing-and-running-scripts)

---

<div class="post-metadata">

**Author:** ![balazs.bayer](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@balazs.bayer](https://community.sonatype.com/u/balazs.bayer)\
**Post date:** [January 10, 2020, 8:48am UTC](https://community.sonatype.com/t/adding-script-to-nexus-oss/3257/3 "2020-01-10T08:48:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andres](https://yyz1.discourse-cdn.com/flex047/user_avatar/community.sonatype.com/andres/32/201_2.png) [@andres](https://community.sonatype.com/u/andres)\
**Post date:** [January 10, 2020, 2:17pm UTC](https://community.sonatype.com/t/adding-script-to-nexus-oss/3257/4 "2020-01-10T14:17:29Z")

</div>

> [@balazs.bayer](#):
>
> 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.

> <https://gist.github.com/HokieGeek/a9d9759e60732e9d4169d40e6279345e>
>
> There are more than three files. show original

The pertinent part is line [L33 in the bash script](https://gist.github.com/HokieGeek/a9d9759e60732e9d4169d40e6279345e#file-rm3-script-sh-L33)

`"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
