Kotlin中的generateStubs配置是什么? [英] What is generateStubs configuration in Kotlin?
问题描述
Kotlin的generateStubs
是什么?这是我在build.gradle
中的配置.
我在此处的公共文档中找不到它: http://kotlinlang.org/docs/reference/kapt.html
kapt {
generateStubs = true
}
如果我在项目中使用Java
和Kotlin(1.2)
,还需要添加吗?
编辑:
如果我在项目中使用Java和Kotlin(1.2),则仍然需要 添加
否,在版本 1.0.4 中引入了注释处理API的新实验性实现.现在,无需在build.gradle
中配置此generateStubs
.
如果要启用以下内容,请在build.gradle
中添加以下内容:
apply plugin: 'kotlin-kapt'
您还必须从build.gradle
generateStubs
配置
但是作为您对generateStubs
上的详细信息的疑问,我保留了原来的帖子.
使用:
将 注意:生成的代码始终位于 生成存根需要相对较多的工作,因为必须解析所有声明,有时知道返回类型需要对表达式进行分析(
工作原理: 存根是编译器生成的中间类,它允许从Kotlin引用生成的"源,否则编译器将无法引用缺少的源. 生成的源代码是在
示例: > 带有Kotlin(1.1.50)注释处理器支持Gradle构建的Dagger2-示例 What is I can not find it in public document here : http://kotlinlang.org/docs/reference/kapt.html If I'm using EDIT: If I'm using Java and Kotlin(1.2) in my project, it is still needed to
add No, With the version 1.0.4 introduces a new experimental implementation of the annotation processing API. Now there is no need to configure this Add the following to your You will also have to remove the But as your question about the Details on Use : Using Note : Generated codes are always in Generating stubs requires relatively much work, because all declarations must be resolved, and sometimes knowing return types requires analysis of expression (bodies of functions or property initializers after the
How this works: Stubs, compiler generated intermediate classes, allows "generated" sources to be referenced from Kotlin otherwise the compiler will not be able to reference the missing sources. Generated source is created in
Example : Dagger2-example with Kotlin (1.1.50) annotation processor support Gradle build 这篇关于Kotlin中的generateStubs配置是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!kapt
与generatestubs = true
结合使用,以便使用诸如dagger 2或dbflow之类的库,这将使编译器能够生成Java和Kotlin之间的互操作性所需的桩类.除非启用generateStubs = true
,否则必须使用Java代码来引用"bootstrap
"(传递给javac
的自定义注释处理器,该注释处理器将加载注释数据并调用其他注释处理器.).生成的sources.pulling 来自 >
Java
中,而不位于Kotlin
中.
=
符号之后的函数或属性初始化器的实体).因此,在kapt
中使用存根会稍微降低构建速度.这就是为什么存根默认情况下处于关闭状态的原因,并且要启用它们,您需要在build.gradle
文件中写入以下内容:kapt {
generateStubs = true
}
"build/generated/source/kapt/main"
中创建的,因为它位于" build
"下,通常从IntelliJ的项目源代码中排除,因此该源代码根将标记在构建脚本本身中.sourceSets {
main.java.srcDirs += [file("$buildDir/generated/source/kapt/main")]
}
generateStubs
for Kotlin? Here is my configuration in build.gradle
. kapt {
generateStubs = true
}
Java
and Kotlin(1.2)
in my project, it is still needed to add?
generateStubs
in build.gradle
.build.gradle
if you want to enable it:apply plugin: 'kotlin-kapt'
generateStubs
config from build.gradle
generateStubs
I keep my old Post as it is.
kapt
with: generatestubs = true
, in order to use libraries like dagger 2 or dbflow,This will enable the compiler to generate stub classes required for interoperability between Java and Kotlin. Unless generateStubs = true
is enabled, "bootstrap
" (A custom annotation processor, which is passed to javac
, loads the annotation data and calls other annotation processors.) Java code is required to reference generated sources.pulled that fromJava
not in Kotlin
.
=
sign). So, using stubs in kapt
slows your build down somewhat. That’s why stubs are off by default, and to enable them you need to write the following in your build.gradle
file:kapt {
generateStubs = true
}
"build/generated/source/kapt/main"
, as this is under "build
", normally excluded from IntelliJ's project sources, this source root will be marked in the build script itself.sourceSets {
main.java.srcDirs += [file("$buildDir/generated/source/kapt/main")]
}