为什么我的Maven插件不会在构建生命周期中运行?

时间:2012-09-12 16:04:57

标签: java maven configuration pom.xml

我尝试使用以下pom部分为我的maven生命周期添加目标。我定义了一个新插件并使用阶段和执行信息对其进行了配置。

<build>
    <pluginManagement>
        <plugins>                   
            <plugin>
                <groupId>org.apache.openjpa</groupId>
                <artifactId>openjpa-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                <includes>**/entity/*.class</includes>
               <addDefaultConstructor>true</addDefaultConstructor>
               <connectionDriverName>com.ibm.db2.jcc.DB2Driver</connectionDriverName>
                        <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                        <sqlFile>${project.build.directory}/database.sql</sqlFile>
                    </configuration>
                    <executions>
                        <execution>
                            <id>sql</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>sql</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>enhancer</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>enhance</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.openjpa</groupId>
                            <artifactId>openjpa</artifactId>

                            <version>2.1.1</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

然后我用mvn:install运行maven但插件没有运行?

2 个答案:

答案 0 :(得分:20)

确保插件存在依赖关系且插件位于build/plugin而不是build/pluginmanagement/plugin

尝试这样的事情:

<dependencies>
    <dependency>
        <groupId>org.apache.openjpa</groupId>
        <artifactId>openjpa</artifactId>
        <version>2.1.1</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>                   
            <plugin>
                <groupId>org.apache.openjpa</groupId>
                <artifactId>openjpa-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                    <includes>**/entity/*.class</includes>
                    <addDefaultConstructor>true</addDefaultConstructor>
                    <connectionDriverName>com.ibm.db2.jcc.DB2Driver</connectionDriverName>
                    <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                    <sqlFile>${project.build.directory}/database.sql</sqlFile>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>sql</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>sql</goal>
                    </goals>
                </execution>
                <execution>
                    <id>enhancer</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

答案 1 :(得分:10)

pluginManagement应该配置插件,在命令行调用。

如果你想将插件绑定到某个执行阶段 - 只需将其移动到pom.xml的build-&gt; plugins部分