Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse project does not recognize Swagger Codegen artefacts

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?

like image 651
IcedDante Avatar asked Apr 24 '26 04:04

IcedDante


2 Answers

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.

like image 159
Torsten Dreyer Avatar answered Apr 25 '26 18:04

Torsten Dreyer


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>
like image 35
JSamir Avatar answered Apr 25 '26 16:04

JSamir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!