springspring-bootmavenopenapi-generator

Can I force a specific Spring Boot version when using OpenAPI Generator Maven plugin?


I'm using the Maven plugin from OpenAPI Generator (version 7.12.0) in my project. It works fine and everything is well generated, but it uses Spring Boot version 3.1.3 (which come with some nice vulnerabilities). I've just updated my project to SB 3.4.4, and it would be nice if the generated code could use that version too, or at least one that doesn't have any vulnerabilities.

Is it any way to force this? I've looked at the doc and I didn't find any mention to this.

Edit: To add some info and clarify, it's a multi module application and the parent POM has the version 3.4.4 on it. The module where I generated the code uses that version too, however, the POM generated by OpenAPI has the 3.1.3.

Edit2: Here is the plugin configuration

        <plugin>
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>${openapi.maven.plugin.version}</version>
            <configuration>
                <configOptions>
                    <useSpringBoot3>true</useSpringBoot3>
                    <useJakartaEe>true</useJakartaEe>
                </configOptions>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>${project.basedir}/src/main/resources/contract/openapi.yml</inputSpec>
                        <generatorName>spring</generatorName>
                        <generateAliasAsModel>true</generateAliasAsModel>
                        <generateApiTests>false</generateApiTests>
                        <generateModelTests>false</generateModelTests>
                        <configOptions>
                            <dateLibrary>java8-localdatetime</dateLibrary>
                            <interfaceOnly>true</interfaceOnly>
                            <java8>true</java8>
                            <library>spring-boot</library>
                            <additionalModelTypeAnnotations>
                                @com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
                                @lombok.extern.slf4j.Slf4j
                                @lombok.Data
                            </additionalModelTypeAnnotations>
                            <requestMappingMode>api_interface</requestMappingMode>
                            <modelPackage>${project.groupId}.model</modelPackage>
                            <apiPackage>${project.groupId}.api</apiPackage>
                            <invokerPackage>${project.groupId}.invoker</invokerPackage>
                        </configOptions>
                        <globalProperties>
                            <skipFormModel>false</skipFormModel>
                        </globalProperties>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Edit3: Ok, so I found out the issue. I just had to add this to the configuration to set the SB version I wanted :

<parentArtifactId>spring-boot-starter-parent</parentArtifactId>
<parentGroupId>org.springframework.boot</parentGroupId>
<parentVersion>3.4.4</parentVersion>

Solution

  • I had the same issue with a parent build.gradle (generating a pom.xml). I could solve it through adding the following details in the openApiGenerate step:

    configOptions.put("parentOverridden", "true")
    additionalProperties = [
        parentGroupId    : 'org.springframework.boot',
        parentArtifactId : 'spring-boot-starter-parent',
        parentVersion    : '3.4.4',
        library          : 'spring-boot',
    ]
    

    Setting it up in maven should be similar or even simpler.