在多模块项目中创建Spring Boot本地镜像

4
我正在尝试使用GraalVM和Spring Boot构建本地镜像。我的项目有几个模块。当我尝试构建本地镜像时,我遇到了以下错误:Error: Please specify class (or <module>/<mainclass>) containing the main entry point method. (see --help) 当我在父POM文件的属性中定义mainClass路径(org.example.api.Application)时,我遇到了以下错误:Error: Main entry point class 'org.example.api.Application' neither found on the classpath nor on the modulepath. 我应该如何定义包含GraalVM主类的模块?

你能把一个小的复现程序放到GitHub上吗? - ozkanpakdil
1个回答

0
在您的父POM文件中(其中您声明了所有模块),使用以下语法:
<modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
</modules>

使用最新的Spring Boot BOM作为父依赖

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

然后覆盖本地配置文件

<profiles>
    <profile>
        <id>native</id>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>build-image</id>
                                <goals>
                                    <goal>compile-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>
</profiles>

在你的模块中(需要本地构建时),你可以设置以下构建配置:

<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>
        </plugin>
    </plugins>
</build>

此时,您可以使用mvn -Pnative clean package编译项目。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接