4

When running a maven package goal

mvn clean package

The build throws the error:

goal org.springframework.boot:spring-boot-maven-plugin:3.0.0-M1:repackage failed: Unable to load the mojo 'repackage' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.0.0-M1' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/springframework/boot/maven/RepackageMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

my JAVA_HOME is pointing to jdk1.8.0_73

How can i get spring-boot-maven-plugin running with repackage goal?

Below is the maven build configuration in my module.

<build>
<resources>
    <resource>
        <directory>resources</directory>
    </resource>
</resources>
<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
            <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
            <webResources>
                <resource>
                    <directory>src/main/resources</directory>
                    <include>*.*</include>
                    <targetPath>/WEB-INF/classes</targetPath>
                </resource>
                <resource>
                    <directory>src/main/webapp/errors</directory>
                    <include>*.*</include>
                    <targetPath>/errors/</targetPath>
                </resource>
            </webResources>
        </configuration>
    </plugin>

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <mainClass>com.services.MyAApp</mainClass>
            <layout>war</layout>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

</plugins>
Leo
  • 43
  • 1
  • 1
  • 5
  • You seemed to try to use spring boot version 3.0.0-M1 which requires JDK17... you can not compile nor use it with JDK8. – khmarbaise Feb 05 '22 at 21:58
  • so sounds like the spring-boot-maven-plugin does not pick the same version as that of the spring-boot-starter. I have my my started defined as part of the spring-boot dependency management. – Leo Feb 08 '22 at 07:20
  • The question is why do you have maven-war-plugin configured ? I suppose your issue is you are not using the spring boot parent? Or you are using the spring-boot-dependencies as BOM which could also be a problem.. Also why have you changed the default directories? does not really make sense – khmarbaise Feb 08 '22 at 07:27
  • #Spring-boot-parent: Is added as part of dependency-management in my parent module. In addidition i have to use a custom parent #maven-war-plugin: I am packaging the app as a war. – Leo Feb 09 '22 at 19:52
  • #maven-war-plugin: i have got rid of the custom packaging, assuming it could cause issues while repackage. So default directories should not be impacted in my opinion. – Leo Feb 09 '22 at 20:07

1 Answers1

13

Version of 'spring-boot-maven-plugin' plugin used in you pom.xml is 3.0.0-M1, which can be used only with Java 17 or newer. Switch to 2.5.7, if it's really version which you want to use for spring boot project.

rufanov
  • 3,266
  • 1
  • 23
  • 41
  • 1
    Well i had to explicitly specify the version of the plugin to resolve this issue. The version was not managed by the spring-boot parent added as part of my managed-dependencies. Appreciate the support rufanov and @khmarbaise – Leo Feb 09 '22 at 20:07
  • 2.6.9 is work for me.thanks – Mr Lou Feb 22 '22 at 07:45