1

I was trying to set my project source and target to Java 1.8 in my pom.xml and found out that it can be done both ways:

  1. Set in properties tag:

    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    
  2. Configure in plugin:

    <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    
    </pluginManagement>
    

Given a choice I would prefer option #1 since it's shorter but what really is the difference between the two?

superigno
  • 994
  • 2
  • 12
  • 24

1 Answers1

2

It's equivalent. In fact maven-compiler-plugin's <source> tag uses <maven.compiler.source> property and <target> uses property <maven.compiler.target> property: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

So if you only want to set up these two properties, you can happily use properties, but plugin is more flexible, because it has lots of other configurations which can be set up (in the wild I've seen: fork, annotationProcessors, compilerArgs and other tags)

jirka.pinkas
  • 918
  • 6
  • 21