How to minimize maven pom.xml

非 Y 不嫁゛ 提交于 2019-12-13 03:04:34

问题


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>
...

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?

EDIT: 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.


回答1:


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.

UPD:

example:

...
<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>             

...



来源:https://stackoverflow.com/questions/46774727/how-to-minimize-maven-pom-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!