如果在pluginManagement下定义了插件,则maven目标无法正确执行

Pan*_*kaj 6 maven-plugin maven

我有maven-jaxb2-plugin.我生成jaxb对象并在其他类项目中引用它.我已经在pluginManagement标记下放了jaxb插件和编译器插件.Maven正在执行编译阶段而不是生成阶段,就好像我删除了pluginManagement标记一样,它工作正常,首先生成阶段执行并生成所有jaxb对象,然后执行编译阶段.由于pluginManagement标记,我的项目无法编译.pluginManagement标记是否仅用于定义父pom中的所有插件,以便子pom可以引用这些插件?我的项目不是一个多模块项目.

   <pluginManagement>       
      <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaDirectory>${basedir}/src/main/resources/schema</schemaDirectory>
                <generatePackage>com.common.dto</generatePackage>
                <schemaIncludes>
                    <include>*.xsd</include>
                </schemaIncludes>
                <removeOldOutput>false</removeOldOutput>
                <strict>false</strict>
                <verbose>true</verbose>
                <forceRegenerate>true</forceRegenerate>
                <extension>true</extension>
            </configuration>
        </plugin>
    </plugins>
 </pluginManagement>
Run Code Online (Sandbox Code Playgroud)

Pat*_* M. 7

是的,<pluginManagement>用于创建即用型配置,但不会自动激活您的插件 - 您仍需要包含它们.所以实际上你是对的,<pluginManagement>,就像<dependencyManagement>在父pom中非常有用,可以集中插件配置和依赖管理.

实际上,在正确的模块中"声明"您的插件可以从更紧凑的语法中获益:

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

    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)