【问题标题】:maven goal doesn't execute properly if plugins are defined under pluginManagement如果插件在 pluginManagement 下定义,maven 目标将无法正确执行
【发布时间】:2012-08-20 09:00:23
【问题描述】:

我有 maven-jaxb2-plugin。我生成 jaxb 对象并将其引用到其他项目类中。我已将 jaxb 插件和编译器插件放在 pluginManagement 标记下。 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>

【问题讨论】:

    标签: maven maven-plugin


    【解决方案1】:

    是的, 用于创建即用型配置,但不会自动激活您的插件 - 您仍然需要包含它们。 所以实际上你是对的,,就像 在父 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>
    

    【讨论】:

      猜你喜欢
      • 2017-01-29
      • 2019-07-09
      • 1970-01-01
      • 1970-01-01
      • 2021-04-22
      • 2016-05-10
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多