Using NetBeans to Build a Custom Maven Plugin from an Archetype
NetBeans makes Maven plugin development approachable because the IDE exposes the project structure, lifecycle, dependencies and generated sources in one workspace. Starting from a project archetype gives you a repeatable foundation rather than an empty directory filled with manually copied configuration. Learn more about The Role Of Exploratory Testing In A Devops Culture.html.
A custom plugin is useful when a team needs a build step that standard Maven plugins do not provide. Examples include checking internal API rules, generating deployment descriptors, validating a company-specific folder layout or producing reports for a Java EE application.
For Australian development teams, this approach suits distributed projects running across Sydney, Melbourne, Brisbane and Perth. A clean archetype can help standardise builds across offices, contractors and government suppliers, where reproducible Maven configuration is often more valuable than a clever one-off script.
NetBeans also makes it practical to inspect older examples and IDE features. The NetBeans archive provides useful background when you need to compare Maven support across releases or find related Java development guidance.
| Approach | Best use | Main advantage | Common drawback |
|---|---|---|---|
| Empty Maven project | Small experimental goal | Maximum control | More setup and configuration |
| Standard plugin archetype | General-purpose Mojo | Fast, conventional structure | Some generated files need editing |
| Custom project archetype | Repeated internal tooling | Consistent team scaffolding | Requires maintenance |
| Existing plugin fork | Specialised extension | Reuses mature code | Upgrade and licensing effort |
Why Start With An Archetype
A Maven archetype is a template that generates a project from known coordinates, properties and source files. For a plugin, it creates the pom.xml, a Mojo implementation, test folders and the metadata needed by Maven’s plugin tooling.
The standard plugin archetype is a sensible starting point, while a custom archetype becomes valuable after the first plugin has been used several times. For example, a Melbourne consultancy might generate the same compliance plugin for several council projects, with company repositories, Java versions and test conventions already embedded.
Set Up The NetBeans Workspace
Install a current JDK and Maven, then open NetBeans and verify the configured Java platform under the IDE’s Java settings. Use a project directory that is easy to locate from a terminal, such as ~/dev/maven-tools, rather than a synchronised folder that may introduce file-locking issues.
Create the project from the Maven archetype catalogue or generate it with the command line and open the resulting pom.xml in NetBeans. A useful checklist before editing includes:
- Confirm the selected JDK matches the project’s compiler release.
- Check that Maven can reach your configured repository mirror.
- Use a group ID owned by your organisation.
- Set a clear artifact ID for the plugin.
- Commit the generated project before making structural changes.
This arrangement works well on a home NBN connection or a corporate network where repository access can be slower during the busy morning period. Keeping dependencies modest also helps developers working from regional areas or travelling between client sites.
Define The Plugin Project
Open the generated POM and replace placeholder coordinates with values such as au.example.build:quality-maven-plugin. Set the project version, licensing information and Maven Plugin API dependencies deliberately. The maven-plugin packaging value tells Maven that this project produces a plugin rather than an ordinary JAR.
The generated source normally contains a class extending AbstractMojo. Its annotations declare the goal name, default phase and required project context. Keep the first goal narrow: a validator that scans files or project metadata is easier to understand than a plugin that also modifies source code, deploys artefacts and sends notifications.
Implement A Useful Mojo
A Mojo is the executable unit behind a Maven goal. Inject configuration with fields annotated by @Parameter, obtain the current MavenProject when needed and write messages through the supplied Log interface. Avoid direct access to NetBeans APIs; the plugin should run from Maven in continuous integration as well as inside the IDE.
For example, a validate-layout goal could inspect src/main/java, reject forbidden directories and fail the build with a clear MojoFailureException. Make paths portable with java.nio.file.Path, and avoid assumptions about Windows or Unix separators. This matters for Australian teams whose developers may use Windows laptops while CI runs Linux containers in Sydney or Canberra.
Test Through A Generated Project
Unit tests should cover valid input, missing files, malformed configuration and expected failure messages. Then create a small sample Maven application that invokes the plugin in its validate phase. This fixture tests the plugin as a consumer would use it, including parameter interpolation and lifecycle behaviour.
Exploratory checks are useful when the goal touches different project layouts or operating systems. The discussion of exploratory testing offers relevant context for combining planned automated checks with purposeful investigation, especially before a plugin is introduced into a large delivery pipeline.
Run mvn verify from NetBeans and from a terminal. Compare the output, generated reports and exit codes. Testing both paths catches configuration differences that can otherwise surprise a Brisbane team when a local build succeeds but a hosted Linux agent rejects the project.
Package And Document The Plugin
Use the Maven Plugin Plugin to generate descriptors and goal documentation during the build. Give every parameter a useful description, state its default and document whether it is required. A concise JavaDoc guide can help when setting a consistent documentation standard for public classes and configuration APIs.
The generated README should show installation, a minimal POM example and expected output. Add integration-test instructions for maintainers, and explain compatibility with Maven and Java versions. For formatting consistency, connect the project’s checks to a Checkstyle workflow so contributors receive the same feedback in NetBeans and on CI.
Publish And Maintain The Archetype
Install the plugin locally with mvn install, then invoke it from a separate sample application using its group ID, artifact ID and version. When the behaviour is stable, publish it to an internal repository or Maven Central according to your organisation’s release policy. Australian businesses working with public-sector procurement should retain release notes, source provenance and security review records.
- Keep plugin goals backward-compatible where possible.
- Test every supported Java and Maven combination.
- Sign released artefacts when repository policy requires it.
- Version breaking configuration changes clearly.
- Remove unused generated examples before release.
If the template itself will be reused, create a dedicated archetype project with filtered properties for package names, versions and organisation details. Tag both the plugin and archetype repositories, and document which template version created each project. That small discipline prevents an “arvo” maintenance session from turning into detective work across several nearly identical builds.