6

I am using the swagger codegen maven plugin to generate a server stub from a swagger spec. If I run mvn compile then it generates properly and compiles the project. However, sometimes I want to run just the generate.

Specifically, I'd like to avoid both compiling the whole project and also running another plugin (checkstyles) which runs in the validate phase. Ideally, I'd like to generate the generated classes from the swagger spec and compile those classes but not the project as a whole.

The use case here is that while developing I may need to update the spec and re-generate at points when the project as a whole isn't valid (or won't be, with the new spec). I've read that you can use "prefix:goal". I've tried the following, but none work:

mvn swagger-codegen-maven-plugin:generate
mvn swagger-codegen:generate
mvn swagger:generate
mvn codegen:generate

It gives (e.g.)

No plugin found for prefix 'codegen' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories

I also read that you could use "groupid:artificatid:version_goal" so I tried:

mvn io.swagger:swagger-codegen-maven-plugin:2.4.0-SNAPSHOT:generate

This seems to get further but gives an error

Failed to execute goal io.swagger:swagger-codegen-maven-plugin:2.4.0-SNAPSHOT:generate (default-cli) on project com.carus.api.base: The parameters 'inputSpec', 'language' for goal io.swagger:swagger-codegen-maven-plugin:2.4.0-SNAPSHOT:generate are missing or invalid

My pom structure is slightly complex. There are several APIs. Each is in some ways their own project. They have a common parent pom with the execution goal in, and the project pom only sets certain variables. The variable used as inputSpec is defined in the project pom, but the one for language in the base pom. (The .base project mentioned here is actually where the base pom is, and is an abstract package (<packaging>pom</packaging>). If I specify a specific project I get the same error but referring to that project.

Questions:

  1. Can I even achieve what I want (generate code from the spec and compile just that code but not the whole project) with a goal?
  2. How to find out what "prefix" to use for the "prefix:goal" syntax?

The closest I have come is run mvn generate-sources -Dcheckstyle.skip=true. This generates but I don't think it compiles the generated classes. So I then have to clean the project in Eclipse to trigger it to recompile.

Adam
  • 6,539
  • 3
  • 39
  • 65

1 Answers1

0
  1. How to find out what "prefix" to use for the "prefix:goal" syntax?

The prefix for the plugin should be in this file: "swagger-maven-plugin-2.3.1.jar/META-INF/maven/com.github.kongchen/swagger-maven-plugin/plugin-help.xml".

    <plugin>
        <name>Swagger Maven Plugin</name>
        ...
        <goalPrefix>swagger</goalPrefix>
        ...
Hari Samala
  • 159
  • 1
  • 4
  • Hmm... Can't find that file in my local .m2 I do have swagger-codegen-maven-plugin-2.4.7.jar and looking in the plugin-help there but it gives the goalPrefix as swagger-codegen. I have tried both that and the swagger you suggest and they didn't work, hence the question... – Adam Nov 15 '19 at 17:38