我有一个使用exec-maven-plugin运行swagger-codegen的maven项目,该项目在子目录中生成一个新的maven项目。我想要的是与继续构建生成的项目相同的Maven流程。
我认为将生成的项目目录声明为模块似乎不起作用,因为maven首先处理所有pom.xml文件,然后开始构建(因此,当需要时,生成的项目尚不存在)。
我想我可以从exec-maven-plugin再次调用一个新的maven进程(尽管我不确定查找诸如maven二进制文件的使用位置以及目标是什么等细节很容易)。希望有人可以提出一种更优雅的方法。
你可以用
下面是在这种情况下如何使用Exec插件的示例:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>build-module</id>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>mvn</executable>
<arguments>
<argument>clean</argument>
<argument>install</argument>
</arguments>
<workingDirectory>${basedir}\module-name</workingDirectory>
</configuration>
</plugin>
如果您需要不同的依赖关系来执行它,并且不想将它们添加为项目的一部分,则还可以按此处所述定义它们,Exec插件将在执行过程中使用插件依赖关系。还请确保正确设置workingDirectory
以便执行。
尽管Invoker插件是为在Maven插件开发期间运行集成测试而定义的,但在这种情况下,它也可能满足您的需求。下面是一个可能的示例:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.7</version>
<configuration>
<pom>${basedir}/module-dir/pom.xml</pom>
<streamLogs>true</streamLogs>
<failIfNoProject>true</failIfNoProject>
<goals>
<goal>clean</goal>
<goal>package</goal>
</goals>
</configuration>
<executions>
<execution>
<id>build-module</id>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.8.3</version>
</dependency>
</dependencies>
</plugin>
我还建议检查Invoker插件的运行目标的其他选项。
在这两种方法中,您都应确保在生成阶段之后执行此插件,然后检查Maven阶段流程(即,如果您在该generate-sources
阶段生成项目,则该项目的执行/构建可能会在该process-resources
阶段进行) 。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句