简体   繁体   中英

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?

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>

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.

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.

此时的答案是,将生成的源文件夹添加到构建路径似乎是强制性的。

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