2017-10-16 112 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