如何最小化 maven pom.xml [英] How to minimize maven pom.xml

查看:71
本文介绍了如何最小化 maven pom.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 spring-boot Maven 项目(Maven 3.5,Java 8).因为在我的项目中使用Swagger Codegen生成类,pom.xml的plugins"标签越来越大:

I am working on a spring-boot maven project (Maven 3.5, Java 8). Because of using Swagger Codegen in my project to generate classes, "plugins" tag of the pom.xml is getting bigger:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin> 
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.2.3</version>
            <executions>
                <execution>
                    <id>file1</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>src/main/resources/swagger/../file1.json</inputSpec>
                        <generateApis>false</generateApis>
                        <generateSupportingFiles>false</generateSupportingFiles>
                        <generateApiDocumentation>false</generateApiDocumentation>
                        <modelPackage>com.bla.bla.model</modelPackage>
                        <templateDirectory>src/main/resources/swagger/templates</templateDirectory>
                        <language>spring</language>
                        <modelNamePrefix>ABC</modelNamePrefix>
                        <configOptions>
                            <interfaceOnly>true</interfaceOnly>
                            <java8>true</java8>
                        </configOptions>
                    </configuration>
                </execution>
                <execution>
                    <id>file2</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>src/main/resources/swagger/.../file2.json</inputSpec>
                        <generateApis>false</generateApis>
                        <generateSupportingFiles>false</generateSupportingFiles>
                        <generateApiDocumentation>false</generateApiDocumentation>
                        <modelPackage>com.bla.bla.model</modelPackage>
                        <templateDirectory>src/main/resources/swagger/templates</templateDirectory>
                        <language>spring</language>
                        <modelNamePrefix>ABC</modelNamePrefix>
                        <configOptions>
                            <interfaceOnly>true</interfaceOnly>
                            <java8>true</java8>
                        </configOptions>
                    </configuration>
                </execution>
...

如果我在另一个 xml 文件中移动一些插件,是否可以将这个 xml 文件包含到 pom.xml 中?如果不可能,那么我怎样才能最小化这个文件?

If I move some plugins in another xml file, is it possible to include this xml file into pom.xml? If it isn't possible, then how can I minimize this file?

这个问题不是是否有可能拆分 maven pom 文件?.我的项目还不算大.只有 pom.xml 文件越来越大,所以没有必要将我的代码分成模块并以具有父子 pom.xml 文件的方式组织它.我需要一些不同的东西.

This question is not a duplicate of Is it possible to split maven pom files?. My project hasn't been big yet. Only pom.xml file is getting bigger, so there is no necessity to seperate my codes into modules and organize it in a way of having parent-child pom.xml files. I need something different.

推荐答案

您可以在 元素中定义通用插件属性一次,然后为每次执行仅定义特定配置.即 src/main/resources/swagger/../file1.json

You can define common plugin properties in <pluginManagement> element once and then for each execution define only specific configurations. i.e. <inputSpec>src/main/resources/swagger/../file1.json</inputSpec>

或者您可以在另一个父项目中执行相同的操作(),并在所有子项目中仅放置特定配置.

Or you can do the same (<pluginManagment>) in another parent project and in all children put only specific configurations.

更新:

示例:

...
<build>
  <pluginManagement>
    <plugins>
        <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.2.3</version>
            <configuration>
                <generateApis>false</generateApis>
                <generateSupportingFiles>false</generateSupportingFiles>
                <generateApiDocumentation>false</generateApiDocumentation>
                <modelPackage>com.bla.bla.model</modelPackage>
                <templateDirectory>src/main/resources/swagger/templates
                </templateDirectory>
                <language>spring</language>
                <modelNamePrefix>ABC</modelNamePrefix>
                <configOptions>
                    <interfaceOnly>true</interfaceOnly>
                    <java8>true</java8>
                </configOptions>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>
<plugins>
    <plugin>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>file1</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>src/main/resources/swagger/../file1.json</inputSpec>
                </configuration>
            </execution>
            <execution>
                <id>file2</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <inputSpec>src/main/resources/swagger/.../file2.json</inputSpec>
                </configuration>
            </execution>
        </executions>
    </plugin>
  </plugins>
</build>             

...

这篇关于如何最小化 maven pom.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆