4

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.

px5x2
  • 1,495
  • 2
  • 14
  • 29
  • How is the generated project built? I haven't used swagger, but i guess if you are trying to build the generated project within the same invocation of maven that generates the code, it's no surprise that the dependencies used are from the generator's pom file. If however the actual build is done in a separate invocation of maven then that seems very strange. – Joakim Z Sep 23 '16 at 10:38
  • 1
    Actually maven-compiler-plugin compiles sources under generated-sources directory as a default action. Maybe maven invoker plugin would be worth trying in this case. – px5x2 Sep 23 '16 at 11:54
  • One solution, albeit not an especially good one, would be to rename the dependencies used in either of the projects so that they are unique between projects. That way there won't be any mixup. By the way, are the dependencies used by the projects internal ones? Otherwise I can't really see the problem. – Joakim Z Sep 27 '16 at 08:52

1 Answers1

2

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>
tswanson-cs
  • 106
  • 13