【报错记录】解决Kotlin编写SpringBoot项目报:Cannot inline bytecode built with JVM target 17 into bytecode that is

完整标题

解决用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刷新完成后,编译就不会再报错了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值