首页 > 解决方案 > Maven 插件即使未在其中声明也会运行部分

问题描述

我有一个父 pom,在下面<pluginManagement>我有一个maven-install-plugin,如下所示:

<artifactId>parent-project</artifactId>
<groupId>com.abc</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
                <executions>
                    <execution>
                        <id>abc</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>com.abc.a</groupId>
                            <artifactId>test</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <file>${basedir}/lib/test.jar</file>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
   </pluginManagement>
   <plugins> <!--empty for demo purposes--> </plugins>
</build>

这是我的一个子项目的 pom.xml:

  <parent>
    <artifactId>parent-project</artifactId>
    <groupId>com.abc</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <groupId>com.abc</groupId>
  <artifactId>child</artifactId>
  <version>1.0-SNAPSHOT</version

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
     <plugins> <!--empty for demo purposes--> </plugins>
  </build>

我还没有<plugins>在父项目和子项目的部分中定义 maven-install-plugin 但是为什么在我运行 pom.xml 时它仍在执行?当我运行我的孩子 pom.xml 时,如何防止它执行?

标签: mavenpom.xmlmaven-pluginparent-pommaven-install-plugin

解决方案


推荐阅读