https://github.com/c0d3d/plugin-repeater-maven-plugin
https://github.com/c0d3d/plugin-repeater-maven-plugin
dry macro maven plugin template xml
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/c0d3d/plugin-repeater-maven-plugin
- Owner: c0d3d
- License: apache-2.0
- Created: 2017-08-06T21:22:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-05-22T19:13:16.000Z (about 4 years ago)
- Last Synced: 2025-08-02T15:25:41.062Z (11 months ago)
- Topics: dry, macro, maven, plugin, template, xml
- Language: Java
- Size: 70.3 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Plugin repeater maven plugin [](https://travis-ci.org/c0d3d/plugin-repeater-maven-plugin) [](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.nlocketz.plugins%22%20a%3A%22plugin-repeater-maven-plugin%22)
Table of contents
=================
* [Summary](#summary)
* [Simple Example](#simple-example)
* [Default Variable Groups](#default-variable-groups)
* [Conditional Inclusion](#conditional-xml-inclusion)
## Summary
The plugin repeater maven plugin allows you to follow the [DRY principal](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) when writing your POM files.
If you've ever had to write a very similar plugin execution dozens of times then this is the plugin for you.
The plugin repeater plugin lets you repeat a plugin execution with different variables substituted.
All the examples in this README assume that we have a fictional plugin, `adder-maven-plugin`, that adds numbers. Anywhere you see ``
means that we've left out the plugin GAV as well as any tags that aren't necessary. This may mean it is in the `contentPlugin` section of a repeater plugin
configuration or a plugin inside a pom's `plugins` section. The context should provide that information for you.
## Simple Example
Say we wanted to add 5 sets of two numbers. Normally you'd have to write something like this:
fake.plugin.group
adder-maven-plugin
0.0.0
first-number-add
add
1
2
second-number-add
add
3
4
third-number-add
add
5
6
four-number-add
add
7
8
fifth-number-add
add
9
10
With the plugin repeater maven plugin you can just write:
com.nlocketz.plugins
plugin-repeater-maven-plugin
LATEST
run-addings
repeat
1
2
3
4
5
6
7
8
9
10
fake.plugin.group
adder-maven-plugin
0.0.0
repeat-add
add
@nOne@
@nTwo@
## Default Variable Groups
If you have some repetitions that all use a certain variable with a certain value, except 1, you'd have to repeat that variable in the repetitions (violating the DRY principal).
Fear not! We have thought of this, and added a feature called `repetitionGroup`s that allow you to set defaults for certain repetitions, and override it for others.
Here is an example:
run-addings
repeat
2
2
3
4
4
...
...
which is equivalent to:
repeat-add
add
2
2
repeat-add
add
2
3
repeat-add
add
4
4
You can even nest these as deeply as you want!
run-addings
repeat
2
2
10
-1
...
...
is equivalent to:
repeat-add
add
10
2
repeat-add
add
2
-1
##### Small gotcha
Due to limitations on maven's XML, you cannot currently do something like this:
run-addings
repeat
2
2
...
...
## Conditional XML Inclusion
The plugin-repeater-maven-plugin also supports conditional inclusion of XML for content plugins.
Currently you can only make the decision based on whether a filter variable is defined for the current repetition or not.
In order to conditionally include a tag, `myTag` inside the configuration of your content plugin you can do the following:
@myVar@
This includes `myVarValue` if `myVar` has a definition for the current repetition.
An important note for this is that a failed condition excludes *everything* within the failing tag.
Any nested XML tags will also be excluded as well as any attributes or string contents.
The plugin-repeater-maven-plugin also supports the `unless` attribute.
Here is a toy usage:
run-addings
repeat
1
2
5
fake.plugin.group
adder-maven-plugin
0.0.0
repeat-add
add
@nOne@
0
@nTwo@
which equivalent to:
repeat-add
add
1
2
repeat-add
add
0
5