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

2022-09-03 03:38:09

我试图用下面的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


答案 1

确保存在对插件的依赖关系,并且插件不在 中。build/pluginbuild/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>

答案 2

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

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


推荐