Skip to content

Add first Maven Java plugin tutorial - #24

Open
Ndacyayisenga-droid wants to merge 4 commits into
mainfrom
tutorial/first-java-plugin-17
Open

Ndacyayisenga-droid wants to merge 4 commits into
mainfrom
tutorial/first-java-plugin-17

Conversation

@Ndacyayisenga-droid

@Ndacyayisenga-droid Ndacyayisenga-droid commented Aug 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace the plugin-developer tutorial stub with a hands-on Maven 3 Java plugin guide (issue Write your first Maven Plugin in Java (Tutorial) #17).
  • Walk through creating a Mojo, installing the plugin, running it, configuring parameters, and optional prefix/POM setup.

Test plan

  • Follow the tutorial steps on Maven 3.9+ and confirm sayhi prints the expected greeting
  • Confirm mvn validate, mvn compile, and mvn install succeed for the sample project
  • Confirm -Dsayhi.greeting=... works before adding POM configuration
  • Confirm hello:sayhi works after adding sample.plugin to pluginGroups
  • Confirm POM <greeting>Welcome</greeting> prints Welcome

Closes #17

@github-actions

Copy link
Copy Markdown

Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/

@Ndacyayisenga-droid
Ndacyayisenga-droid force-pushed the tutorial/first-java-plugin-17 branch from 01d9339 to 9aba4e7 Compare August 12, 2026 16:15
@Ndacyayisenga-droid
Ndacyayisenga-droid force-pushed the tutorial/first-java-plugin-17 branch from 9aba4e7 to 2a31ee6 Compare August 12, 2026 16:16
@github-actions

Copy link
Copy Markdown

Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/

1 similar comment
@github-actions

Copy link
Copy Markdown

Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/

@github-actions

Copy link
Copy Markdown

Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/

@@ -1,7 +1,474 @@
# Write your first Java plugin

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Write your first Java plugin
# Write your first Maven plugin 3 in Java

New-Item -ItemType File -Path "$root/pom.xml" -Force | Out-Null
```

**Verify:** list the tree with `ls -R hello-maven-plugin` (macOS / Linux) or `tree hello-maven-plugin` if you have it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a verify step also for Windows user

@github-actions

Copy link
Copy Markdown

Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/

ls ~/.m2/repository/sample/plugin/hello-maven-plugin/1.0-SNAPSHOT/
```

You should see `plugin.xml` and a JAR named `hello-maven-plugin-1.0-SNAPSHOT.jar`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin.xml will only exist in target directory and into jar, not in m2 directory


## Step 5: Run the `sayhi` goal

Stay inside `hello-maven-plugin/` and invoke the goal with its full coordinates:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not required stay in plugin project directory, after install, plugin can be used in any directory / project


Typing the full coordinates every time gets old quickly.
The artifactId `hello-maven-plugin` follows the `${prefix}-maven-plugin` convention, so Maven derives the prefix `hello`.
Maven does not search arbitrary plugin groupIds for prefix resolution unless they are listed in `pluginGroups`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have in project which use a plugin defined it in buid/pluginManagments or buid/plugins - prefix will be also resolved in project

## Step 8: Configure the parameter in the POM (optional)

You can set the same parameter in `pom.xml` instead of `-D`.
Add a `<plugins>` block inside the existing `<build>` section, next to `<pluginManagement>`:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pluginManagement can also contains configuration

</build>
```

The configuration element name (`greeting`) matches the Mojo field name.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be changed by @Parameter(name = "..." ...)

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${maven.plugin.tools.version}</version>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add

         <executions>
            <execution>
              <id>help-mojo</id>
              <goals>
                <goal>helpmojo</goal>
              </goals>
            </execution>
          </executions>

we will have generated an help goal for plugin

<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Hello Maven Plugin</name>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also add

  <prerequisites>
    <maven>3.9.0</maven>
  </prerequisites>

with minimal required version of Maven by plugin

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write your first Maven Plugin in Java (Tutorial)

3 participants