0

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.

séan35
  • 966
  • 2
  • 13
  • 37
  • Possible duplicate of [Is it possible to split maven pom files?](https://stackoverflow.com/questions/2271082/is-it-possible-to-split-maven-pom-files) – OldProgrammer Oct 16 '17 at 16:18
  • See the OldProgrammer comment for the usual maven way. You could try polyglot maven (https://github.com/takari/polyglot-maven) to use pom file in other format than XML and choose whatever dialect you want among the supported dialects. If your project is small enough you could also consider switching to gradle – Xavier Bouclet Oct 16 '17 at 16:23

1 Answers1

0

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>             

...

Vadim
  • 4,027
  • 2
  • 10
  • 26
  • 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 think I have to use modules and parent-child pom.xml hierarchy to implement your recommendations, right? – séan35 Oct 17 '17 at 11:25
  • Not necessary. You can define common properties in `` once in the same pom.xml and then in your actual `` `` or `` set only specific properties. – Vadim Oct 17 '17 at 15:48
  • something like in added example for the "same pom" configuration. – Vadim Oct 17 '17 at 15:54
  • thank u so much. I couldn't find such an example around internet. I edit pom.xml and now it works! – séan35 Oct 18 '17 at 08:06
  • 1
    You are welcome. keep in mind - Maven configuration is hierarchical from `` i.e. you can have ultimate parent with very common configurations, then another set of parents with more specific configurations and so on down to the actual projects. All configurations are inherited and also overload by next level. And it is not related to `` hierarchy. `` defines what other projects to build all together. Particular modules can have different parents with different configurations defined. Very often both hierarchies used together, but it is not necessary. – Vadim Oct 18 '17 at 16:05