完整标题

解决用Maven框架Kotlin语言编写的SpringBoot项目编译过程报:

Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option

前言

我用Maven构建并用Kotlin编写的SpringBoot项目启动报:Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option。查了一下网上全是用Gradle编译的项目,而没有Maven的,搞得我又只能自己来解决了。

解决方法

很简单,用idea创建一个自动生成的Maven构建Kotlin语言的SpringBoot项目,看看它能否正常启动。

然后很尴尬,也报这个错……

然后我在pom.xml中找到了端倪:

默认的kotlin-maven-pluginjvmTarget是1.8,而我这边需要编译为17,这就是问题的关键所在,将这里的1.8改为17,刷新一下Maven问题就解决了。

而我自己从0搭建的Kotlin项目也只需要将这个plugin复制过去即可。

            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <args>
                        <arg>-Xjsr305=strict</arg>
                    </args>
                    <compilerPlugins>
                        <plugin>spring</plugin>
                    </compilerPlugins>
                    <jvmTarget>17</jvmTarget>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

Maven刷新完成后,编译就不会再报错了。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐