2017-10-16 108 views
0

我正在开发一个spring-boot maven项目(Maven 3.5,Java 8)。因为在我的项目中使用扬鞭代码生成,生成类,pom.xml中的“插件”标签越来越大:如何最小化maven pom.xml

<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文件的方式对其进行组织。我需要不同的东西。

+0

的可能的复制[?是否有可能分裂的Maven POM文件(https://stackoverflow.com/questions/ 2271082/is-it-it-it-split-maven-pom-files) – OldProgrammer

+0

查看OldProgrammer对常用maven方式的评论。您可以尝试使用polyglot maven(https://github.com/takari/polyglot-maven)来使用除XML以外的其他格式的pom文件,并在支持的方言中选择您想要的任何方言。如果你的项目足够小,你也可以考虑切换到gradle –

回答

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>    

...

+0

我的项目还没有大。只有pom.xml文件变得越来越大,所以没有必要将我的代码分离到模块中,并以具有父 - 子pom.xml文件的方式对其进行组织。我想我必须使用模块和父子pom.xml层次结构来实现您的建议,对吧? –

+0

没必要。你可以在''中定义一个共同的属性,一次在同一个pom.xml中,然后在你实际的''或''中设置特定的属性。 – Vadim

+0

类似于“同样的pom”配置的添加示例。 – Vadim