4

I have this plugin configured in parent pom

 <properties>
        <java.version>1.7</java.version>
        <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
 </properties>
 ...
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArgument>-XDignore.symbol.file</compilerArgument>
                </configuration>
            </plugin>
         </plugins>
    </pluginManagement>
</build>

And this in the child

<build>
    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
    </plugins>
</build>

When i run maven update project on both projects , i expect that child change JRE to 1.7, but it doesn't, i and i cannot figure it out why. If i put the configuration in the child then it works... Do you know what am i doing wrong?

pjanssen
  • 1,065
  • 13
  • 35
jscherman
  • 5,839
  • 14
  • 46
  • 88
  • Are you sure the parent is correctly listed in the element? – Uday Shankar Jun 24 '15 at 20:56
  • @UdayShankar Yep, i am sure. I just not put that part to not extend the post – jscherman Jun 24 '15 at 21:12
  • To verify, what do the configurations for maven-compiler-plugin show when you run `mvn help:effective-pom` from the child project? Does `mvn help:effective-pom -Djava.version=1.7` show anything different? – Don Bottstein Jun 25 '15 at 00:16
  • @DonBottstein No, there is no difference between those outputs – jscherman Jun 25 '15 at 16:30
  • @jscherman Based on that, it doesn't look like an issue with the pom .. more likely your IDE (Eclipse?). I don't know if this will be helpful, but here's a link to a troubleshooting guide for the problem you are seeing: https://maven.apache.org/plugins/maven-eclipse-plugin/trouble-shooting/jdk-being-used-is-different-than-expected.html – Don Bottstein Jun 25 '15 at 19:08
  • I solved it putting the plugin in the parent outside pluginManagement and adding true, so that way i delete that plugin from the childs and that is being inherited. Not the best solution but the best i could do. Thanks anyways! – jscherman Jun 25 '15 at 19:14

2 Answers2

1

I was having the same issue in my build process. The build was failing with the following error:

[INFO] Compiling 2 source files to /project/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /project/src/test/java/com/example/MyClass.java:[18,63] lambda expressions are not supported in -source 1.7
(use -source 8 or higher to enable lambda expressions)

and the reason was due to the compilation of test files not having the correct java level set. The following configuration worked for me:

In the parent:

<properties>
  <java.version>1.8</java.version>
  <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
</properties>
...
<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${maven-compiler-plugin.version}</version>
        <configuration>
          <source>${java.version}</source>
          <target>${java.version}</target>
          <testSource>${java.version}</testSource>
          <testTarget>${java.version}</testTarget>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

In the child:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
    </plugin>
  </plugins>
</build>
cjackson
  • 1,637
  • 1
  • 13
  • 25
0

A typical issue is that the maven-compiler-plugin version is too old. The release option was introduced in version 3.6. Try specifying a newer version of maven-compiler-plugin in the parent POM and use the release option to specify the Java version. From JDK 9, the release option replaces source and target.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.11.0</version>
  <configuration>
    <release>11</release>
  </configuration>
</plugin>
lars
  • 640
  • 4
  • 10