首页 文章

如何最小化maven pom.xml

提问于
浏览
0

我正在开发一个spring-boot maven项目(Maven 3.5,Java 8) . 由于在我的项目中使用Swagger Codegen来生成类,pom.xml的“plugins”标记变得越来越大:

<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中?如果不可能,那么如何最小化此文件?

编辑:这个问题不是Is it possible to split maven pom files?的重复 . 我的项目还不够大 . 只有pom.xml文件变得越来越大,因此没有必要将我的代码分成模块并以拥有父子pom.xml文件的方式组织它 . 我需要不同的东西 .

1 回答

  • 0

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

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

    UPD:

    例:

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

    ...

相关问题