Create a maven Repository by the groovy API

875 views
Skip to first unread message

Dan Steffen

unread,
Mar 20, 2017, 9:54:39 AM3/20/17
to Nexus Users
Hello,

I try to create a maven Repository by the groovy API and use at the moment this code example:

import org.sonatype.nexus.blobstore.api.BlobStoreManager
import org.sonatype.nexus.repository.storage.WritePolicy
import org.sonatype.nexus.repository.maven.VersionPolicy
import org.sonatype.nexus.repository.maven.LayoutPolicy

repository
.createMavenHosted('private')

repository
.createMavenHosted('private-again', BlobStoreManager.DEFAULT_BLOBSTORE_NAME, true, VersionPolicy.RELEASE,
       
WritePolicy.ALLOW_ONCE, LayoutPolicy.STRICT)

and after the Installation of groovy on the Server I copied the following jar-File in the ~/.groovy/lib Directory:

  • nexus-blobstore-api-3.0.1-01.jar
  • nexus-core-3.0.1-01.jar
  • nexus-repository-3.0.1-01.jar
  • nexus-repository-maven-3.0.1-01.jar
but if I run the Script I get the error:

Caught: java.lang.NoClassDefFoundError: org/sonatype/goodies/lifecycle/Lifecycle
java.lang.NoClassDefFoundError: org/sonatype/goodies/lifecycle/Lifecycle
Caused by: java.lang.ClassNotFoundException: org.sonatype.goodies.lifecycle.Lifecycle

and now I have no idea how can I create a repository by the groovy API and hope someone here can give me a full example how groovy basically in combination with nexus works.

I would be very thanksful because this are my first steps with groovy too.
best regards
Dan


Peter Lynch

unread,
Mar 20, 2017, 11:18:03 AM3/20/17
to Dan Steffen, Nexus Users
On Mon, Mar 20, 2017 at 10:54 AM, 'Dan Steffen' via Nexus Users <nexus...@glists.sonatype.com> wrote:
Hello,

I try to create a maven Repository by the groovy API and use at the moment this code example:

import org.sonatype.nexus.blobstore.api.BlobStoreManager
import org.sonatype.nexus.repository.storage.WritePolicy
import org.sonatype.nexus.repository.maven.VersionPolicy
import org.sonatype.nexus.repository.maven.LayoutPolicy

repository
.createMavenHosted('private')

repository
.createMavenHosted('private-again', BlobStoreManager.DEFAULT_BLOBSTORE_NAME, true, VersionPolicy.RELEASE,
       
WritePolicy.ALLOW_ONCE, LayoutPolicy.STRICT)

and after the Installation of groovy on the Server I copied the following jar-File in the ~/.groovy/lib Directory:

  • nexus-blobstore-api-3.0.1-01.jar
  • nexus-core-3.0.1-01.jar
  • nexus-repository-3.0.1-01.jar
  • nexus-repository-maven-3.0.1-01.jar
but if I run the Script I get the error:

The Java classpath for your script is incomplete. Some of the classes referenced import other class files that are in none of these jars.

The method you are trying to use to setup the classpath by putting jars inside ~/.groovy/lib is a bit cumbersome.

It would be much easier in theory for you to use an IDE that supports loading Maven projects ( IDEA Community Edition https://www.jetbrains.com/idea/download/ ) and load this project:



Caught: java.lang.NoClassDefFoundError: org/sonatype/goodies/lifecycle/Lifecycle
java.lang.NoClassDefFoundError: org/sonatype/goodies/lifecycle/Lifecycle
Caused by: java.lang.ClassNotFoundException: org.sonatype.goodies.lifecycle.Lifecycle

and now I have no idea how can I create a repository by the groovy API and hope someone here can give me a full example how groovy basically in combination with nexus works.

I would be very thanksful because this are my first steps with groovy too.
best regards
Dan


--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.
To post to this group, send email to nexus...@glists.sonatype.com.
To view this discussion on the web visit https://groups.google.com/a/glists.sonatype.com/d/msgid/nexus-users/f33db0dd-8ce6-403b-80b2-3dcb9a580374%40glists.sonatype.com.
For more options, visit https://groups.google.com/a/glists.sonatype.com/d/optout.

Dan Steffen

unread,
Mar 21, 2017, 7:10:41 AM3/21/17
to Nexus Users, dan.ste...@googlemail.com
Hello Peter,

first of all I would like to thanks for your help. Now I have create a json-File with the content:

{
"name": "maven2",
"type": "groovy",
"content": "repository.createMavenHosted('private-again', 'default', true, VersionPolicy.SNAPSHOT, WritePolicy.ALLOW_ONCE, org.sonatype.nexus.repository.maven.LayoutPolicy.STRICT)"
}

this file I upload with the command:

curl -v -u admin:admin123 --header "Content-Type: application/json" 'http://localhost:8081/nexus/service/siesta/rest/v1/script/' -d @aaaa.json

and get a 204, but if I try to rund the script by

curl -v -X POST -u admin:admin123 --header "Content-Type: text/plain" "http://localhost:8081/nexus/service/siesta/rest/v1/script/maven2/run"

I get the error:

400 Bad Request: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: VersionPolicy for class: Script8"

This confused me a little bit because this json-Script works after I uploaded it:

{
"name": "maven",
"type": "groovy",
"content": "repository.createMavenHosted('private')"
}

Maybe someone can tell me where is my mistake?
best regards
Dan


PS
I also try
{
"name": "maven2",
"type": "groovy",
"content": "repository.createMavenHosted('private-again', 'default', true, org.sonatype.nexus.repository.maven.policy.VersionPolicy.SNAPSHOT, org.sonatype.nexus.repository.storage.WritePolicy.ALLOW_ONCE, org.sonatype.nexus.repository.maven.LayoutPolicy.STRICT)"
}


but then I get the error:
"javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: org for class: Script9"
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.

Peter Lynch

unread,
Mar 21, 2017, 11:17:07 AM3/21/17
to Dan Steffen, Nexus Users
On Tue, Mar 21, 2017 at 8:10 AM, 'Dan Steffen' via Nexus Users <nexus...@glists.sonatype.com> wrote:
Hello Peter,

first of all I would like to thanks for your help. Now I have create a json-File with the content:

{
"name": "maven2",
"type": "groovy",
"content": "repository.createMavenHosted('private-again', 'default', true, VersionPolicy.SNAPSHOT, WritePolicy.ALLOW_ONCE, org.sonatype.nexus.repository.maven.LayoutPolicy.STRICT)"
}

this file I upload with the command:

curl -v -u admin:admin123 --header "Content-Type: application/json" 'http://localhost:8081/nexus/service/siesta/rest/v1/script/' -d @aaaa.json

and get a 204, but if I try to rund the script by

curl -v -X POST -u admin:admin123 --header "Content-Type: text/plain" "http://localhost:8081/nexus/service/siesta/rest/v1/script/maven2/run"

I get the error:

400 Bad Request: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: VersionPolicy for class: Script8"

Why did you remove the import statements? The problem is the script cannot find VersionPolicy, which it would have found if you had kept the import statements ie. 

import org.sonatype.nexus.blobstore.api.BlobStoreManager
import org.sonatype.nexus.repository.storage.WritePolicy
import org.sonatype.nexus.repository.maven.VersionPolicy
import org.sonatype.nexus.repository.maven.LayoutPolicy

 
This confused me a little bit because this json-Script works after I uploaded it:

{
"name": "maven",
"type": "groovy",
"content": "repository.createMavenHosted('private')"
}

Maybe someone can tell me where is my mistake?
best regards
Dan


PS
I also try
{
"name": "maven2",
"type": "groovy",
"content": "repository.createMavenHosted('private-again', 'default', true, org.sonatype.nexus.repository.maven.policy.VersionPolicy.SNAPSHOT, org.sonatype.nexus.repository.storage.WritePolicy.ALLOW_ONCE, org.sonatype.nexus.repository.maven.LayoutPolicy.STRICT)"
}


but then I get the error:
"javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: org for class: Script9"

A different problem now that is groovy syntax specific. Add the import statements you had previously.

You may prefer to test the script inside the Execute Script scheduled task in the UI first.

 
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.

To post to this group, send email to nexus...@glists.sonatype.com.
Reply all
Reply to author
Forward
0 new messages