問題描述
對于Java,我們是這樣排除的:
With Java, we are excluding like this:
java {
srcDir 'src'
exclude '**/myTests/**'
}
我想用 kotlin 做同樣的事情.試圖在配置 kotlin 的官方文檔中找到一些關于此的文檔,但沒有成功.我所期望并已經(jīng)嘗試過的(當然沒有成功):
I want to make the same thing with kotlin. Trying to find some docs on this in official documentation configuring kotlin with no success. What i've expected and already tried (and of course with no success):
kotlin {
srcDir 'src'
exclude '**/myTests/*.kt'
}
推薦答案
java {
srcDir 'src'
exclude '**/myTests/*.kt'
}
沒有 Kotlin 相關的配置.
There is no Kotlin related configuration.
我為什么這么說,我將所有 kotlin 文件放入 kotlin 目錄,將 java 文件放入 java 目錄.但是在配置的時候,我放了
Why I am saying this, I have all the kotlin files into kotlin directory and java files into java directory. But while configuring, I have put
sourceSets {
main.java.srcDirs += "src/main/kotlin"
}
這意味著使用 src/main/java
在編譯時也可以從 src/main/kotlin
添加源文件.
this means that with src/main/java
add source files from src/main/kotlin
also while compiling.
這應該可以解決您的問題.
This should solve your issue.
這篇關于如何從 gradle 編譯中排除 kotlin 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!