Sonatype Blog
Latest Posts

Writing a Nexus Plugin Using m2eclipse

January 8, 2010 By Damian Bradicich 10

nexus-small

In this post, I’m going to walk you through the process of creating a new Nexus plugin using the m2eclipse plugin for eclipse from start to finish including all steps in the process.  After reading this post you will know about the easiest way to get started working on your own Nexus plugin.

Some things to note are that I am using the latest m2e 0.9.9 dev build available from the http://m2eclipse.sonatype.org/update-dev update site. I am also using eclipse 3.5.1.  All maven builds have been done using local build of latest maven 3.0-SNAPSHOT, however, that is not a requirement for the plugins to work, just a recommendation as maven 3 (in my opinion) is much better than maven 2 :)

Configuring Your Environment for the Nexus Plugin Project

To successfully create a Nexus Plugin using the Nexus Plugin archetype, you will need to configure your Maven Settings to include both the Sonatype Forge repository and the Central Maven repository. If you are already using Nexus and you have configured your settings.xml to use a single, consolidated repository group, all you need to do is add a proxy repository for the Sonatype Forge repository to your repository group. If you are not using Nexus, you will need to use a settings.xml that resembles the following sample:

<settings>
  <profiles>
    <profile>
      <id>sonatype-forge</id>
      <repositories>
        <repository>
          <id>sonatype-forge</id>
          <url>http://repository.sonatype.org/content/groups/forge/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>sonatype-forge</id>
          <url>http://repository.sonatype.org/content/groups/forge/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>sonatype-forge</activeProfile>
  </activeProfiles>
</settings>

Creating a New Project with the Nexus Plugin Archetype

Let’s start by creating a ‘New Maven Project’ in m2eclipse.

new-project

Select Maven > Maven Project, and click on Next until you reach the archetype selection. On this screen you can search for and select the archetype which will create your new project. Note that you must use the 1.2 version of the nexus-plugin-archetype.

archetype-selection

Enter the GAV (groupId, artifactId, version) params that will uniquely define the plugin, and click on Next.

Targeting the Proper Nexus Version

After supplying the project identifiers, you will see a panel that display the archetype property ${nexusVersion}. This is the version of Nexus that your plugin will target and it will associate your project with the proper set of dependencies for a specific version of Nexus.

gav-params

By default the nexus-plugin-archetype will target Nexus version 1.4.1.   If you are targeting 1.4.1, it is important that you add the following to your project’s dependency management because of a problem w/ the parent POM of Nexus 1.4.1. If you are not tied to using Nexus 1.4.1 we strongly recommend that you update the Nexus version you are targeting 1.4.2-SNAPSHOT and disregard this change. The 1.4.2-SNAPSHOT POMs have been updated properly and they do not require the following dependency management workaround.

<dependencyManagement>
    <dependencies>
        <!- Workaround for swizzle-jira:1.3.3-SONATYPE-2, as it has an incorrect parent ->
        <dependency>
            <groupId>org.codehaus.swizzle</groupId>
            <artifactId>swizzle-jira</artifactId>
            <version>1.3.3-SONATYPE-221</version>
        </dependency>
    </dependencies>
</dependencyManagement>

If you have already generated the project, and you need to change the target Nexus version you will need to edit this new project’s POM. Open up the POM of your Nexus Plugin and find the section that defines properties. You will need to change the nexus-version property to target a Nexus version. After creating a project with the Nexus Plugin archetype, you will see a properties section of the POM that contains a ${nexusVersion} reference as follows:

<project>
  ...
  <properties>
    <!-- Set the Nexus version here, against which you build the plugin -->
    <nexus-version>${nexusVersion}</nexus-version>
  </properties>
  ...
</project>

Click Next after setting the ${nexusVersion}, and voila, we have a nexus-plugin project.

Building and Deploying the Plugin Project

Your new Nexus plugin project has some sample components you can use as a starting point for your own plugin development.

new-project-package-explorer

You can now build this project and expand the bundle right into your nexus installation ${nexus-work-dir}/plugin-repository/

nexus-work-directory-layout

And when Nexus starts it will find the plugin and load it automatically. For this sample plugin, you should see the log message in the Nexus log:

Plugin manager “ACTIVATE” on plugin “org.sonatype.nexus.plugin:test-plugin:0.0.1-SNAPSHOT” was successful.

As expected, you are now able to properly use the new plexus resource, I used curl to perform a GET against the default /sample/hello service added to my Nexus instance. The best part is that we have achieved everything you see above with absolutely zero code, Maven Archetypes really do simplify things for you :)

curl-example

Categories: m2eclipse, Nexus Tags: , , ,

  • http://gryphon366.xanga.com/758613909/different-panama-excursions/ living in panama

    will smith and jada pinkett open marriage…

    [...]well as fencing leader For Each Henrik Ling (1777-1839), who examined therapeutic massage on China[...]…

  • http://einstein.drexel.edu/liki/index.php/User_talk:Brittyboop74v Nerf gun

    My opinion is ……

    There are definitely numerous particulars like that to take into consideration. That may be a nice level to carry up. I offer the thoughts above as normal inspiration but clearly there are questions like the one you deliver up the place a very powerful…

  • http://treadmilllady.orbs.com/ Nordictrack treadmill reviews

    will smith scientology video…

    [...]gentle Lennox right after he heard 3 different and totally different statements from three [...]…

  • http://www.wildplanettours.com/tours/india India Tour Packages

    will smith movies 2009…

    [...]last Oct and maintained her unbeaten record [...]…

  • http://freeipad2now.com/how-to-get-free-ipad-2/ how to get a free ipad 2

    Great article…

    An fascinating discussion is worth comment. I believe that you should write extra on this topic, it won’t be a taboo subject however usually people are not sufficient to talk on such topics. To the next. Cheers…

  • http://www.flavorconnect.com/ online dating community

    greenpeace organization history…

    [...]Your Victoria Royals can be main youngster hockey workforce taking part in inside Western [...]…

  • http://gunnisongambit.com/story.php?title=free-ipad-2-proven-method-as-seen-on-tv free ipad 2

    Just read this ……

    I precisely wanted to say thanks all over again. I’m not certain what I would’ve gone through in the absence of the type of tips contributed by you directly on that area …

  • http://dentral-care-and-oral-health.webs.com/apps/blog/show/7583984-philips-sonicare-flexcare-plus-rechargeable-toothbrush Philips Sonicare FlexCare Plus HX6972/10 Rechargeable Toothbrush

    greenpeace jobs chicago…

    [...]practice in the location of game[...]…

  • http://alertarticles.info/dynamic-and-active-apartments-near-ucf.html apartments near ucf

    sopa passed congress…

    [...]Your Victoria Royals can be significant youngster hockey workforce enjoying inside Western [...]…

  • http://oralhealth.jimdo.com/2011/06/22/philips-sonicare-flexcare-plus/ sonicare flexcare plus

    will smith open marriage…

    [...]against Lennox and his family members is now out of the fingers of Belfast Metropolis Council [...]…

blog comments powered by Disqus
Sonatype Promotion Subscribe via RSS