maven-compiler-plugin in parent pom

In the parent you need to define it in <pluginManagement/> rather than <plugins/>

https://maven.apache.org/pom.html#Plugin_Management

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one

<build>
    <finalName>ParentPOMProj</finalName>

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

As mentioned in the docs, the child project also needs to reference the plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <!-- inherits config from parent: can override if required -->
        </plugin>
    </plugins>
</build>

After researching further, I understood that the java version in maven-compiler-plugin in parent pom applies to the child POMs but not to the parent itself. Basically, most of the time, it is not recommend to keep any source code in parent project, it is barely to handle all the build configuration for the child modules. Here are the updated POMS :


PARENT POM

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.mymaven.parentpom.example</groupId>
<artifactId>ParentPOMProj</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>

<name>ParentPOMProj</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <finalName>ParentPOMProj</finalName>

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


<modules>
    <module>ModuleOne</module>
</modules>


CHILD POM

http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0

<parent>
    <groupId>com.mymaven.parentpom.example</groupId>
    <artifactId>ParentPOMProj</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<groupId>com.mymaven.parentpom.example.module</groupId>
<artifactId>ModuleOne</artifactId>
<packaging>jar</packaging>
<version>0.0.2-SNAPSHOT</version>
<name>ModuleOne</name>
<url>http://maven.apache.org</url>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

enter image description here