kotlin java mixed code maven package implementation

  • 2021-09-05 00:02:51
  • OfStack

Introduction to Kotlin

Kotlin is a new programming language for Java platform. Kotlin is concise, secure, pragmatic, and focused on interoperability with Java code. It can be used almost anywhere Java is used today: server-side development, Android applications, and so on. Kotlin works well with all existing Java libraries and frameworks, and its performance is comparable to that of Java.

Kotlin Features

Kotlin is a statically typed language and supports type derivation, allowing you to maintain correctness and performance while keeping source code concise.
Kotlin supports object-oriented and functional programming styles, enables higher levels of abstraction through first-class functions, and simplifies testing and multithreaded development by supporting immutable values.
It works well in server-side applications fully supporting all existing Java frameworks and providing new tools for common tasks such as generating HTML and persistence.

It also works on Android, thanks to a compact runtime, special compiler support for Android API, and a rich library that provides Kotlin-friendly functions for common Android development tasks.

It is free and open source and fully supports mainstream IDE and build systems.

Kotlin is pragmatic, secure, concise, and interoperable with Java, meaning that it focuses on using proven solutions to handle common tasks, prevent common errors like NullPointerException, support compact and readable code, and provide unlimited integration with Java.

Let's look at kotlin java mixed code maven packaging

Required plug-ins


<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>

Command change

Old


mvn clean package

New


mvn clean kotlin:compile package

Related articles: