You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.1.0+Java17项目执行native-image命令报错求助

问题:Maven执行native-image命令时提示找不到插件前缀

我有一个基于Spring Boot 3.1.0和Java 17的项目,运行状态正常。目前尝试集成GraalVM创建原生容器镜像,执行命令:

mvn native-image:native-image -Dimage=$REPO:$TAG -Djib.container.environment=SPRING_PROFILES_ACTIVE=prod

出现错误提示:

No plugin found for prefix 'native-image' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories

以下是项目的pom.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.xyz</groupId>
    <artifactId>abc</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>app</name>
    <description>app</description>
    <properties>
        <java.version>17</java.version>
        <apache.poi.ooxml.version>4.1.2</apache.poi.ooxml.version>
    <checkstyle-plugin.version>3.2.0</checkstyle-plugin.version>
    <checkstyle.version>10.5.0</checkstyle.version>
  </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>${apache.poi.ooxml.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>ooxml-schemas</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${checkstyle-plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>${checkstyle.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>checkstyle</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <excludes>**/module-info.java,**/target/**/*,**/protocols/**/*</excludes>
                    <consoleOutput>true</consoleOutput>
                    <failsOnError>true</failsOnError>
                    <violationSeverity>warning</violationSeverity>
                    <failOnViolation>true</failOnViolation>
                    <linkXRef>false</linkXRef>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>3.3.2</version>
                <dependencies>
                    <dependency>
                        <groupId>com.google.cloud.tools</groupId>
                        <artifactId>jib-native-image-extension-maven</artifactId>
                        <version>0.1.0</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <pluginExtensions>
                        <pluginExtension>
                            <implementation>com.google.cloud.tools.jib.maven.extension.nativeimage.JibNativeImageExtension</implementation>
                        </pluginExtension>
                    </pluginExtensions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

解决方法

1. 修正命令中的插件前缀

你配置的是native-maven-plugin,对应的Maven命令前缀应为native而非native-image,正确命令如下:

mvn native:native-image -Dimage=$REPO:$TAG -Djib.container.environment=SPRING_PROFILES_ACTIVE=prod

2. (可选)显式指定插件版本

虽然Spring Boot父项目会自动管理native-maven-plugin的版本,若需显式控制,可在pom.xml的properties节点中添加:

<graalvm.buildtools.version>0.9.22</graalvm.buildtools.version>

(Spring Boot 3.1.0对应的默认版本即为0.9.22,可按需调整)

3. 确认GraalVM环境配置

  • 本地需安装GraalVM,且正确配置GRAALVM_HOME环境变量
  • 确保Maven使用的JDK为GraalVM提供的JDK

内容的提问来源于stack exchange,提问作者anonymous

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 22:05:30