如果在pluginManagement下定义了插件,maven目标将无法正确执行 [英] maven goal doesn't execute properly if plugins are defined under pluginManagement

查看:160
本文介绍了如果在pluginManagement下定义了插件,maven目标将无法正确执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have maven-jaxb2-plugin. I generate jaxb objects and refer it in other classes of project.I've put jaxb plugin and compiler plugin under pluginManagement tag. Maven is executing compile phase first than generate phase where as if i remove pluginManagement tag, it works fine, first generate phase gets executed and all jaxb object gets generated and then compile phase gets executed. Due to pluginManagement tag, my project doesn't compile. Is pluginManagement tag used only for defining all the plugins in parent pom so that child pom can refer to these plugins ? My project is not a multi-module project.

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

推荐答案

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

Yes, <pluginManagement> is used to create ready-to-use configurations, but does not automatically activate your plugins - you still need to include them. So in effect you are right, <pluginManagement>, just like <dependencyManagement> are very useful in the parent pom to centralize plugin configurations and dependency management.

有效地,在更正确的模块中声明"您的插件将受益于更紧凑的语法:

Effectively, 'declaring' your plugins in the right module benefits from a much more compact syntax:

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

这篇关于如果在pluginManagement下定义了插件,maven目标将无法正确执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆