Maven继承不适用于pluginManagement

时间:2015-06-24 20:28:57

标签: java maven inheritance multi-module

我在父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>

这在孩子身上

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

当我在两个项目上运行maven更新项目时,我希望孩子将JRE更改为1.7,但它没有,我和我无法弄明白为什么。如果我把配置放在孩子身上然后就行了......你知道我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

我的构建过程中遇到了同样的问题。构建失败,出现以下错误:

[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)

原因是由于编译的测试文件没有正确的java级别设置。以下配置对我有用:

在父母:

<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>

在孩子身上:

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