3

I added Swagger Codegen to my Eclipse project by modifying my pom.xml file directly:

<plugin>
    <!--
        Plugin that provides API-first development using swagger-codegen to
        generate Spring-MVC endpoint stubs at compile time from a swagger definition file
    -->
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>${swagger-codegen-maven-plugin.version}</version>
    <executions>
        <execution>
                <id>generate-swagger-javaclient</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>src/main/resources/swagger/remote-api.json</inputSpec>
                    <language>java</language>
                    <apiPackage>com.myproj</apiPackage>
                    <modelPackage>com.myproj.model</modelPackage>
                    <generateSupportingFiles>true</generateSupportingFiles>
                    <generateApiTests>false</generateApiTests>
                    <configOptions>
                        <dateLibrary>java8</dateLibrary>
                    </configOptions>
                    <library>resttemplate</library>
                </configuration>
            </execution>
        </executions>
    
</plugin>

If I run Maven update or the Maven generate-sources target, I get all the artefacts generated in my Eclipse project's /target/generated-sources/swagger/src folder.

However, Eclipse does not recognize them. Am I supposed to edit my Eclipse build path manually like some commoner, or is Eclipse supposed to recognize this new source folder automatically?

dur
  • 15,689
  • 25
  • 79
  • 125
IcedDante
  • 6,145
  • 12
  • 57
  • 100

4 Answers4

3

You can use build-helper-maven-plugin to add generated sources to you build path, if this plugin itself does not support it.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${project.basedir}/target/generated-sources/</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
dur
  • 15,689
  • 25
  • 79
  • 125
JSamir
  • 1,057
  • 1
  • 10
  • 20
2

In Eclipse 4.9.0 (2018-09) I had to add the generated-sources folder as a source folder for the project like this:

  1. open the "Navigator" view
  2. browse to target/generated-sources (or whatever your folder for the generated sources is).
  3. right-click on that folder
  4. click "Build Path" -> "Use as Source Folder"

Menu Tree Screenshot

Does not solve the "Plugin execution not covered by lifecycle configuration" issue.

Torsten Dreyer
  • 116
  • 1
  • 4
1

The answer, at this time, is that adding the generated source folder to the build path seems to be mandatory.

IcedDante
  • 6,145
  • 12
  • 57
  • 100
  • 4
    In Eclipse Photon using swagger codegen maven plugin v 2.4.5, the generated folder to add is target/generated-sources/swagger/src/main/java and Eclipse recognizes the new classes. But Eclipse still complains "Plugin execution not covered by lifecycle configuration" so the project remains in error status. Is there a solution? – chrisinmtown Apr 26 '19 at 13:10
0

Ctrl+shift+R

Opens 'Open Resource' dialog box. Besides the message line 'Enter Resource name ....' there is a drop down option. When u click it, u get options as 'show status' , 'show derived sources' etc.

You must ensure that 'show derived sources' is checked. Eclipse will start showing swagger generated artifacts as well.

Caffeine Coder
  • 948
  • 14
  • 17