8

Getting error on mvn clean install, trying to generate openapi.json for openAPI spec

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.3.0.RELEASE:start (pre-integration-test) on project abcd: Cou ld not figure out if the application has started: Failed to connect to MBean server at port 9001: Could not invoke shutdown operation: Spring application did not start before the configured timeout (30000ms -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Using below configuration -

<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.4.4</version>
    </dependency>



<plugin>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <apiDocsUrl>http://localhost:8080/v3/api-docs</apiDocsUrl>
                <outputFileName>openapi.json</outputFileName>
                <outputDir>${project.build.directory}</outputDir>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass></mainClass>
            </configuration>
            <executions>
                <execution>
                    <id>pre-integration-test</id>
                    <goals>
                        <goal>start</goal>
                    </goals>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Emilia
  • 81
  • 1
  • 4
  • If you want to generate the OpenAPI spec file without integration-tests, then you can try switching to the [OpenAPI Tools - Swagger Maven Plugin](https://github.com/openapi-tools/swagger-maven-plugin) – Debargha Roy Dec 02 '20 at 11:54
  • @Emilia Did you already solved the issue? I' the same ... – Thilo Schwarz Nov 05 '21 at 21:00

2 Answers2

2

Check the link from the log itself:

http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Unlike many other errors, this exception is not generated by the Maven core itself but by a plugin. As a rule of thumb, plugins use this error to signal a problem in their configuration or the information they retrieved from the POM.

So the best you can actually do is enable full maven logging using switch -X. After that, you should see the leads what is actually wrong, plugin name, phase etc... Something like this:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.7.4:start (pre-integration-test) on project s***r: Could not figure out if the application has started: Failed to connect to MBean server at port 9001: Could not invoke shutdown operation: Connection refused to host: 127.0.0.1; nested exception is: 
[ERROR]     java.net.ConnectException: Connection refused: connect
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.7.4:start (pre-integration-test) on project secure-file-transfer-manager: Could not figure out if the application has started
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
Jozef
  • 1,154
  • 11
  • 7
-2

You are not using the right options:

Make sure you use the right JVM options: -Dspring.application.admin.enabled=true