简体   繁体   中英

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. It outputs the project to generated-sources/swagger/ directory. 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.

Is such configuration possible? I have already read about maven antlr4 and build helper plugins, but they do not seem useful for this purpose.

Use openapi-generator-maven-plugin to generate the source. Than the maven-invoker-plugin to build and test the generated source.

 <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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