本文主要是介绍spring boot maven 添加kotlin编译, java kotlin 混编配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
拿到一个已经有部分业务代码的 java项目 ,使用maven进行构建的。希望能在项目中增加kotlin相关的支持。所以就需要进行kotlin 项目配置,并且不能转化之前的代码,所以就需要java 和 kotlin 混合编译。
说明关键配置
parent 项目的pom 配置
增加依赖配置
<properties><kotlin.version>1.3.50</kotlin.version></properties>
<dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-stdlib-jdk8</artifactId><version>${kotlin.version}</version></dependency><dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-test</artifactId><version>${kotlin.version}</version><scope>test</scope></dependency><dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-reflect</artifactId><version>${kotlin.version}</version></dependency>
增加plugin 进行混编
<build><plugins><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><jvmTarget>1.8</jvmTarget></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.5.1</version><executions><!-- 替换会被 maven 特别处理的 default-compile --><execution><id>default-compile</id><phase>none</phase></execution><!-- 替换会被 maven 特别处理的 default-testCompile --><execution><id>default-testCompile</id><phase>none</phase></execution><execution><id>java-compile</id><phase>compile</phase><goals><goal>compile</goal></goals></execution><execution><id>java-test-compile</id><phase>test-compile</phase><goals><goal>testCompile</goal></goals></execution></executions><configuration><encoding>${project.build.sourceEncoding}</encoding><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>
以上配置完成后,即可在原有java的项目中使用kotlin进行代码编写,并且 编译 打包 都可以正常执行。
这篇关于spring boot maven 添加kotlin编译, java kotlin 混编配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!