Kotlin doesn't compile from src / main / kotlin when using maven

The kotlin compiler seems to only try to compile the .kt files that are in src / main / java and ignore src / main / kotlin. However, everything seems to be linked correctly with the IntelliJ IDE. No mistakes.

Below is my plugin config 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 doesn't seem to start. So I am trying 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 scanned, but not src / main / kotlin.

I don't see anything wrong with my configuration. Any help is appreciated.

+3


source to share


1 answer


You probably need to disable compilation by default as stated 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>

      

+1


source







All Articles