我在gradle项目管理中有模块。有些类是通过注释处理创建的。但毕竟这些自动生成的文件没有进入最后的jar。如何添加它们?
模块的build.gradle:
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation libraries.kotlinStdLib
implementation libraries.rxjava
compile project(':generator:annotation')
kapt project(":generator:processor")
compileOnly project(":generator:processor")
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main.java.srcDirs += "${buildDir.absolutePath}/tmp/kapt/main/kotlinGenerated/"
debug.java.srcDirs += 'src/debug/kotlin'
debug.java.srcDirs += "${buildDir.absolutePath}/tmp/kapt/debug/kotlinGenerated/"
release.java.srcDirs += 'src/release/kotlin'
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
kapt {
generateStubs = true
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath libraries.kotlinPlugin
classpath libraries.kotlinStdLib
}
}
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
生成的文件在此包中可见,由JUnit等测试。此外,Android Studio还可以看到这些文件。
$ find . -type f | grep Fsm*
./build/classes/kotlin/main/com/example/FsmPaymentInteractorImpl.class
./build/classes/kotlin/main/com/example/FsmSettingsInteractorImpl.class
./build/tmp/kapt/main/kotlinGenerated/FsmPaymentInteractorImpl.kt/com/example/FsmPaymentInteractorImpl.kt
./build/tmp/kapt/main/kotlinGenerated/FsmSettingsInteractorImpl.kt/com/example/FsmSettingsInteractorImpl.kt
$
jar中没有文件:
$ find . -name domain.jar | xargs tar tf | grep Fsm
$
想法?
更新
我发现了意外的行为:如果我运行jar
任务两次,所需的文件就会添加到jar中。为什么?
$ ./gradlew -q :domain:jar ; find . -name Fsm* -type f
./domain/build/classes/kotlin/main/com/example/FsmPaymentInteractorImpl.class
./domain/build/classes/kotlin/main/com/example/FsmSettingsInteractorImpl.class
./domain/build/tmp/kapt/main/kotlinGenerated/FsmPaymentInteractorImpl.kt/com/example/FsmPaymentInteractorImpl.kt
./domain/build/tmp/kapt/main/kotlinGenerated/FsmSettingsInteractorImpl.kt/com/example/FsmSettingsInteractorImpl.kt
$ ./gradlew -q :domain:jar ; find . -name Fsm* -type f
./domain/build/classes/kotlin/main/com/example/FsmPaymentInteractorImpl.class
./domain/build/classes/kotlin/main/com/example/FsmSettingsInteractorImpl.class
./domain/build/tmp/kapt/main/classFileStubs/com/example/FsmPaymentInteractorImpl.class
./domain/build/tmp/kapt/main/classFileStubs/com/example/FsmSettingsInteractorImpl.class
./domain/build/tmp/kapt/main/kotlinGenerated/FsmPaymentInteractorImpl.kt/com/example/FsmPaymentInteractorImpl.kt
./domain/build/tmp/kapt/main/kotlinGenerated/FsmSettingsInteractorImpl.kt/com/example/FsmSettingsInteractorImpl.kt
$ find . -name domain.jar | xargs tar tf | grep Fs
com/example/FsmPaymentInteractorImpl.class
com/example/FsmSettingsInteractorImpl.class
$