java 为什么我的 Maven 插件不在构建生命周期中运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12392260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why isn't my Maven plugin run in the build lifecycle?
提问by Kayser
I have tried to add a goal to my maven lifecycle with the following pom part. I defined a new plugin and configured it with phase and execute information.
我尝试使用以下 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>
Then I run maven with mvn:install
But the plugin is not run?
然后我用 maven 运行mvn:install
但是插件没有运行?
回答by Farid
Make sure that there is a dependency on the plugin and that the plugin is in build/plugin
not build/pluginmanagement/plugin
.
确保对插件有依赖性,并且插件build/plugin
不在 not 中build/pluginmanagement/plugin
。
Try with something like this:
尝试这样的事情:
<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>
回答by jdevelop
pluginManagement
is supposed to configure plugin, which is invoked at command line.
pluginManagement
应该配置插件,在命令行调用。
If you want to bind plugin to some execution phase - simply move it into build->plugins section of your pom.xml
如果您想将插件绑定到某个执行阶段 - 只需将其移动到 pom.xml 的 build->plugins 部分