Как создать версию maven-jar-plugin 3.1.2 в pom с помощью swagger-codegen-maven-plugin
Я использую версию swagger-codegen-maven-plugin 2.4.7 для создания проекта. он генерирует версию maven-jar-plugin 2.6, но мне нужна версия 3.1.2.
Есть ли способ создать собственную версию плагина?
сгенерированный pom.xml:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <executions> <execution> <goals> <goal>jar</goal> <goal>test-jar</goal> </goals> </execution> </executions> <configuration> </configuration> </plugin>
хотел pom.xml:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.1.2</version> <executions> <execution> <goals> <goal>test-jar</goal> </goals> </execution> </executions> <configuration> </configuration> </plugin>
1 ответ
Вывод Swagger Codegen основан на шаблонах усов. Например, pom.xml
шаблон для клиента Java + jersey2
библиотека доступна здесь:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache
Swagger Codegen позволяет переопределить встроенные шаблоны с помощью пользовательских шаблонов. Вы можете сделать это следующим образом:
Создать папку (скажем,
codegen-templates
) в вашем проекте.Скачать
pom.mustache
Шаблон из этой ссылки на эту папку.
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustacheИзменить загруженный
pom.mustache
и обновитьmaven-jar-plugin
версия и конфигурация по требованию.В вашей
pom.xml
укажите путь кcodegen-templates
папка в<templateDirectory>
параметр:<plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>2.4.7</version> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <inputSpec>https://petstore.swagger.io/v2/swagger.yaml</inputSpec> <language>java</language> <library>jersey2</library> <!-- The folder containing your custom pom.mustache --> <templateDirectory>${project.basedir}/codegen-templates</templateDirectory> </configuration> </execution> </executions> </plugin>
Теперь Swagger Codegen будет генерировать pom.xml
на основе вашего обычая pom.mustache
шаблон.