SoftwareEntwicklung Beratung Schulung

A coders, hackers heaven.....Hm...I do not think so...

Maven Anti Patterns: Build Helper Maven Plugin

| Comments

In Maven builds I often see a pattern like the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<plugins>
  <plugin>
    <groupId>group</groupId>
    <artifactId>generatorPlugin</artifactId>
    <version>..</version>
    <configuration>
     ...
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>...</version>
    <executions>
      <execution>
        <phase>generate-sources</phase>
        <goals>
          <goal>add-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>target/generated-sources/WHATEVER</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

The generatorPlugin is just a placeholder for different kinds of maven plugins which generate code for example ANTLR4 Maven Plugin, Templating Maven Plugin, JAXB2 Maven Plugin just to mention a few examples here.

Usually this can be reduced to the following:

1
2
3
4
5
6
7
8
9
10
<plugins>
  <plugin>
    <groupId>group</groupId>
    <artifactId>generatorPlugin</artifactId>
    <version>..</version>
    <configuration>
     ...
    </configuration>
  </plugin>
</plugins>

The reason is simple, cause those plugins already handle the task to add the generated source code to the correct parts in Maven to give for example the Maven Compiler Plugin a hint to compile also those generated java code.

Yes I know there are some of such plugins out there which do not do it in the correct way which means you need to add the Build Helper Maven Plugin snippet, but this means those plugins need some improvements. Those plugins violate the Convention over Configuration paradigm. Why? Simply cause you as user need to think about an internal detail of those plugins which is simply wrong. They have to handle that on their own.

A further note here. I do not say Build Helper Maven Plugin is wrong. It is the usage of the Build Helper Maven Plugin in the described relationship.

Comments