The kotlin compiler seems to only be trying to compile .kt files that are in src/main/java, and is ignoring src/main/kotlin. However, everything seems to be linked correctly in the IntelliJ IDE. No errors.
Below is my plugin configuration for kotlin:
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
However, when I run mvn clean install, the kotlin compiler does not seem to run. So I try to run the kotlin compiler directly from the plugin.
[INFO] --- kotlin-maven-plugin:1.1.2:compile (default-cli) @ eagle-client-core ---
[INFO] Kotlin Compiler version 1.1.2
[INFO] Compiling Kotlin sources from [C:\Users\me\workspace\Project\Clients\project-client\project-client-core\src\main\java]
As you can see, src/main/java is getting scanned, but not src/main/kotlin.
I don't see anything obviously wrong with my configuration. Any help is appriciated.
If you still prefer to stick with good old Maven, there is no problem. There is a plugin for it to support Kotlin as well. If you don't have Maven on your machine, you can follow the instructions at https://maven.apache.org/install.html to get it installed on your local machine.
Yes, when targeting the JVM, Kotlin is compiled to JVM *. class files, which is a bytecode format that can later be either interpreted by a JVM, or compiled to the machine code by the JVM during the program run (JIT), or even compiled ahead-of-time (AOT) down to the machine code.
The kotlin-maven-plugin compiles Kotlin sources and modules.
Kotlin lets you choose the version of JVM for execution. By default, the Kotlin/JVM compiler produces Java 8 compatible bytecode.
You would likely need to turn off the default compile as noted in https://kotlinlang.org/docs/reference/using-maven.html#compiling-kotlin-and-java-sources
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<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>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With