Repository Management with Nexus
Repository Management with Nexus

18.18. Using the Nexus Plugin Archetype

To create a new Nexus Plugin, you can use the Nexus Plugin Archetype by running archetype:generate with the following identifiers:

archetypeGroupId
org.sonatype.nexus.archetypes
archetypeArtifactId
nexus-plugin-archetype
archetypeVersion
1.2

Once you run archetype:generate, you will be prompted for the groupId, artifactId, version, and package name for the generated project.

$ mvn archetype:generate -DarchetypeGroupId=org.sonatype.nexus.archetypes \
-DarchetypeArtifactId=nexus-plugin-archetype \
-DarchetypeVersion=1.2
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository missing. Using the one from [org.sonatype.nexus.archetypes:nexus-plugin-archetype:1.2] found in catalog remote
Define value for property 'groupId': : org.sonatype.book.nexus
Define value for property 'artifactId': : sample-plugin
Define value for property 'version':  1.0-SNAPSHOT: :
Define value for property 'package':  org.sonatype.book.nexus: :
[INFO] Using property: nexusVersion = 1.4.1
Confirm properties configuration:
groupId: org.sonatype.book.nexus
artifactId: sample-plugin
version: 1.0-SNAPSHOT
package: org.sonatype.book.nexus
nexusVersion: 1.4.1
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: nexus-plugin-archetype:1.2
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.sonatype.book.nexus
[INFO] Parameter: artifactId, Value: sample-plugin
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: org.sonatype.book.nexus
[INFO] Parameter: packageInPathFormat, Value: org/sonatype/book/nexus
[INFO] Parameter: package, Value: org.sonatype.book.nexus
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: nexusVersion, Value: 1.4.1
[INFO] Parameter: groupId, Value: org.sonatype.book.nexus
[INFO] Parameter: artifactId, Value: sample-plugin
[INFO] project created from Archetype in dir: /Users/anders/dev/sample-plugin
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 54.206s
[INFO] Finished at: Thu Oct 27 11:12:13 CEST 2011
[INFO] Final Memory: 7M/265M
[INFO] ------------------------------------------------------------------------

Once the Archetype plugin has created the project, you will have a project with the layout shown in Figure 18.1, “Layout of a Nexus Plugin Project”.

figs/web/plugdev_filesystem.png

Figure 18.1. Layout of a Nexus Plugin Project


The generated project contains the following classes:

org.sonatype.book.nexus.XYVirusScanner
An implementation of the VirusScanner Interface
org.sonatype.book.nexus.VirusScannerRequestProcessor
A class which customizes the request handling process in Nexus
org.sonatype.book.nexus.VirusScannerRepositoryCustomizer
A class which customizes the repositories affected by the VirusScanner
org.sonatype.book.nexus.VirusScanner
A VirusScanner interface described in Section 18.21, “Creating a Complex Plugin”.
org.sonatype.book.nexus.events.InfectedItemFoundEvent
A simple event which is fired by the VirusScanner
Sonatype Promotion Subscribe via RSS