Add first Maven Java plugin tutorial - #24
Ndacyayisenga-droid wants to merge 4 commits into
Conversation
|
Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/ |
01d9339 to
9aba4e7
Compare
9aba4e7 to
2a31ee6
Compare
|
Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/ |
1 similar comment
|
Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/ |
|
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 | |||
There was a problem hiding this comment.
| # 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. |
There was a problem hiding this comment.
We should add a verify step also for Windows user
|
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`. |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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>`: |
There was a problem hiding this comment.
pluginManagement can also contains configuration
| </build> | ||
| ``` | ||
|
|
||
| The configuration element name (`greeting`) matches the Mojo field name. |
There was a problem hiding this comment.
can be changed by @Parameter(name = "..." ...)
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-plugin-plugin</artifactId> | ||
| <version>${maven.plugin.tools.version}</version> |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
We can also add
<prerequisites>
<maven>3.9.0</maven>
</prerequisites>with minimal required version of Maven by plugin
|
Docs preview for this PR: https://support-and-care.github.io/doc-for-maven/pr/24/ |
Summary
Test plan
sayhiprints the expected greetingmvn validate,mvn compile, andmvn installsucceed for the sample project-Dsayhi.greeting=...works before adding POM configurationhello:sayhiworks after addingsample.plugintopluginGroups<greeting>Welcome</greeting>printsWelcomeCloses #17