如何最小化maven pom.xml
How to minimize maven pom.xml
我正在开发一个 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 文件的方式组织它。我需要一些不同的东西。
您可以在 <pluginManagement>
元素中定义一次通用插件属性,然后为每次执行仅定义特定配置。即 <inputSpec>src/main/resources/swagger/../file1.json</inputSpec>
或者您可以在另一个父项目中执行相同的操作 (<pluginManagment>
),并且在所有子项目中只放置特定的配置。
更新:
示例:
...
<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>
...
我正在开发一个 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 文件的方式组织它。我需要一些不同的东西。
您可以在 <pluginManagement>
元素中定义一次通用插件属性,然后为每次执行仅定义特定配置。即 <inputSpec>src/main/resources/swagger/../file1.json</inputSpec>
或者您可以在另一个父项目中执行相同的操作 (<pluginManagment>
),并且在所有子项目中只放置特定的配置。
更新:
示例:
...
<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>
...