这样的 属性 重写在 Maven3 中有效吗?

Does such property overriding work in Maven3?

我有 parent pom.xml build/pluginManagement/plugins/plugin 部分用于 maven-compiler-plugin。它包含依赖于 属性 ${targetJdk} 的配置,它也在 parent pom 中定义。

我有一个 child pom.xml,它使用 parent 中的 maven-compiler-plugin。 但是 child pom.xml 会用其他值覆盖 ${targetJdk} 属性。

Parent:

<properties>
    <targetJdk>1.8</targetJdk>
</properties>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${targetJdk}</source>
                    <target>${targetJdk}</target>
                    <debug>true</debug>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>       
</build>

Child:

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

所以问题是:当我构建一个 child 工件时,它将使用什么 属性 值?

通常,当您在 child pom 中声明相同的插件 and/or 属性时,您会覆盖 parent.

您的 child 将使用 <targetJdk>1.7</targetJdk>

希望对您有所帮助。

为了确定始终使用有效的 Pom

帮助:有效的pom