Junchen Liu
Junchen Liu

Reputation: 5624

Maven Compiler Plugin

I know Maven compiler plugin by DEFAULT is bind to :

life cycles, in general without specifying addition configuration, we don't have to explicitly define it in our POM, but I still seen experienced developer putting things like this in their POM, e.g

<build>
    <plugins>
        <plugin>
            <artifactId>maven-shade-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
    </plugins>
</build>

I wander what's the point? and why is he doing this?

Upvotes: 2

Views: 4047

Answers (2)

khmarbaise
khmarbaise

Reputation: 97399

If they put such things in their pom's they don't understand Maven. You should define the version of the plugins your are using in your build. This is done by:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin<artifactId>
        <version>3.1</version>
        <configuration>
          <target>1.6</target>
          <source>1.6</source>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin<artifactId>
        <version>2.3</version>
      </plugin>
    </plugins>
  </pluginManagement> 
</build>

This should be usually located into a pom file known under Company POM which defines versions of plugins for projects within a company.

Furthermore based on the life-cycle definition in Maven the Maven Super POM which contains the default bindings there you could see that particular plugins versions are defined.This means if you upgrade your Maven version you start using different plugin versions which is fact not the best related to build reproducibility. So the best practice is to define all used plugins like here as an example.. Based on the definition you shouldn't need to mention anything in your build-tag area if you have a defined packaging type (This is one of those Convention Over Configuration paradigm hints).

Upvotes: 1

user944849
user944849

Reputation: 14951

For the shade plugin, he is probably using POM inheritance. Look in the parent POM hierarchy for a pluginManagement section, there is probably shade plugin configuration there that he is pulling into this module.

For the compiler plugin, I do not know. You are correct, for jar/war/ear/ejb projects Maven will pull in the compiler config automatically, even if he has defined specific configuration in a parent POM's pluginManagement section.

Upvotes: 1

Related Questions