16

我尝试使用以下 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>

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

4

2 回答 2

32

确保该插件存在依赖关系并且该插件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>
于 2012-09-12T16:26:01.657 回答
17

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

如果您想将插件绑定到某个执行阶段 - 只需将其移至 pom.xml 的 build->plugins 部分

于 2012-09-17T13:58:49.913 回答