编译Kotlin和Java代码

为了编译混合代码的应用,Kotlin编译器必须在Java编译器之前执行。在Maven中的表现形式就是kotlinmaven- plugin必须在maven-compiler-plugin之前执行,这需要将插件放置在maven-compiler-plugin插件位置之前。

<build>
    <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>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <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>
</plugins>
</build>

results matching ""

    No results matching ""