简体   繁体   English

在 generate-sources 目录下编译生成的 maven 项目

[英]Compile generated maven project in generated-sources directory

I am generating a complete maven project (with its own pom.xml) with swagger codegen maven plugin.我正在使用 swagger codegen maven 插件生成一个完整的 maven 项目(带有自己的 pom.xml)。 It outputs the project to generated-sources/swagger/ directory.它将项目输出到 generated-sources/swagger/ 目录。 However java sources in this directory are compiled against dependencies that are residing in my generator project's pom.xml, not against the one which is generated.但是,此目录中的 java 源代码是针对驻留在我的生成器项目的 pom.xml 中的依赖项编译的,而不是针对生成的依赖项进行编译。

Is such configuration possible?这样的配置可以吗? I have already read about maven antlr4 and build helper plugins, but they do not seem useful for this purpose.我已经阅读了有关 maven antlr4 和构建辅助插件的文章,但它们似乎没有用于此目的。

Use openapi-generator-maven-plugin to generate the source.使用 openapi-generator-maven-plugin 生成源码。 Than the maven-invoker-plugin to build and test the generated source.比 maven-invoker-plugin 来构建和测试生成的源代码。

 <plugin>
   <groupId>org.openapitools</groupId>
   <artifactId>openapi-generator-maven-plugin</artifactId>
   <version>${openapi-generator-maven-plugin.version}</version>
   <executions>
     <execution>
       <goals>
         <goal>generate</goal>
       </goals>
       <configuration>
         <inputSpec>swagger.yaml</inputSpec>
         <generatorName>java</generatorName>
         <skipValidateSpec>true</skipValidateSpec>
         <output>${project.build.directory}/generated-sources/openapi</output>
       </configuration>
     </execution>
   </executions>
 </plugin>

 <plugin>
   <artifactId>maven-invoker-plugin</artifactId>
   <version>${maven-invoker-plugin.version}</version>
   <configuration>
     <pom>${project.build.directory}/generated-sources/openapi/pom.xml</pom>
   </configuration>
   <executions>
     <execution>
       <phase>process-sources</phase>
       <goals>
         <goal>run</goal>
       </goals>
     </execution>
   </executions>
 </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM