[英]Ignore maven plugin during a build
在构建或部署期间,如何忽略插件( maven-antrun-plugin
)?
我正在从IDL工具(用C编写)生成源文件。 我使用maven-antrun-plugin
进行了源代码生成,并将其应用于了generate-sources
阶段。 IDL工具生成的java源代码与build-helper-maven-plugin
存储在生成的sources文件夹中,并最终作为源包含在jar包装中。 完善!
这是我在Maven构建中使用的:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="target/generated-sources/" />
<!-- other task stuff here -->
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/gen-java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
但是,现在的问题是,我们的团队被指示不要在持续集成(CI)环境中使用IDL工具。 由于未安装IDL工具,插件在CI中将失败。 结果,我必须将生成的源(以及src / main / java下的其他代码)检入到我们的GIT存储库中。
我想能仍然运行maven-antrun-plugin
,但是,从分离它generated-sources
相或任何生命周期,以使CI环境可以运行我的身材。 进行更改时,我将手动/本地运行插件,以便生成源,然后签入GIT存储库。
这有可能吗? 在构建或部署期间如何忽略 maven-antrun-plugin
?
正如评论者(Jarrod Roberson)所建议的那样,可以使用maven 配置文件忽略maven-antrun-plugin
插件中的源代码生成。
具体来说,添加如下所示的profiles
块可解决该问题。 default-profile
文件default-profile
文件已激活 ; 它不包含maven-antrun-plugin
块。 但是, generate-source-profile
确实包含将启动源生成的maven-antrun-plugin
。
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>generate-sources-profile</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="target/generated-sources/" />
<!-- other task stuff here -->
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
因此,持续集成(CI)工具将执行正常的构建和部署(mvn部署)。 当我想生成源代码时,我将通过执行mvn clean install -P generate-sources-profile
来运行“生成源代码”配置mvn clean install -P generate-sources-profile
。
您可以使用配置文件或仅跳过maven-antrun-plugin执行
跳过 -指定Antrun执行是否应该被跳过。
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<skip>${skipAntRunForMe}</skip>
<tasks>
<mkdir dir="target/generated-sources/"/>
<!-- other task stuff here -->
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
并使用参数-DskipAntRunForMe
来实现目标
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.