Comments (18)
Fixed in e81d01f and will be available in 1.0.9. There should no longer workarounds be needed.
from ksp.
For now, I've manually supported this like so
sourceSets {
main {
java {
srcDir(file("build/generated/ksp/src/main"))
}
}
test {
java {
srcDir(file("build/generated/ksp/src/test"))
}
}
}
from ksp.
For android folks who want to set kotlin sourceSets, we can configure it this way
android.applicationVariants.all { variant ->
kotlin.sourceSets {
def name = variant.name
getByName(name) {
kotlin.srcDir("build/generated/ksp/$name/kotlin")
}
}
}
from ksp.
As a slight modification to the above, here's an approach that's a little more compact and flexible (for Android projects):
applicationVariants.all {
val variantName = name
sourceSets {
getByName("main") {
java.srcDir(File("build/generated/ksp/$variantName/kotlin"))
}
}
}
from ksp.
After upgrading to Android Studio Electric Eel the following solution didn't work anymore:
android {
libraryVariants.all {
kotlin.sourceSets {
getByName(name) {
kotlin.srcDir("build/generated/ksp/${name}/kotlin")
}
}
}
}
But this one seems to work fine:
android {
kotlin {
sourceSets {
debug {
kotlin.srcDir("build/generated/ksp/debug/kotlin")
}
release {
kotlin.srcDir("build/generated/ksp/release/kotlin")
}
}
}
}
from ksp.
For android folks who want to set kotlin sourceSets, we can configure it this way
android.applicationVariants.all { variant -> kotlin.sourceSets { def name = variant.name getByName(name) { kotlin.srcDir("build/generated/ksp/$name/kotlin") } } }
For build.gradle.kts
android.applicationVariants.all {
kotlin {
sourceSets {
getByName(name) {
kotlin.srcDir("build/generated/ksp/$name/kotlin")
}
}
}
}
from ksp.
I'd like to warn about issues in previously mentioned options.
applicationVariants.all {
val variantName = name
sourceSets {
getByName("main") {
java.srcDir(File("build/generated/ksp/$variantName/kotlin"))
}
}
}
sourceSets
is not variant aware.
This code adds generated code from all build variants to the main source set.
E.g. generated code for "debug" and "release" build variants will be in "main" source set.
Print out source sets to see the final state.
It goes against the idea of build variants. This is probably not what you want.
configure<BaseExtension> {
buildVariants.configureEach {
sourceSets {
named(name).configure {
java.srcDir("build/generated/ksp/$name/kotlin")
}
}
}
}
This alternative has another issue.
It adds generated code as input and breaks build cache.
I'll show this on example.
First clean build:
./gradlew :module:clean :module:kspReleaseKotlin -Dorg.gradle.caching.debug=true
Appending input file fingerprints for 'source' to build cache key: xxx - RELATIVE_PATH{/project/module/src/main/java/.../Clazz.kt' / ...}
There were only sources as input for this task.
Now, lets run again:
./gradlew :module:kspReleaseKotlin -Dorg.gradle.caching.debug=true
Appending input file fingerprints for 'source' to build cache key: yyy - RELATIVE_PATH{/project/module/build/generated/ksp/release/kotlin/<generated>, /project/module/src/main/java/.../Clazz.kt' / ...}
Here we see generated files as an addition to original sources.
It causes a cache miss. The output is not "stable".
from ksp.
@Suppress("UnstableApiUsage")
sourceSets.configureEach {
kotlin.srcDir("$buildDir/generated/ksp/$name/kotlin/")
}
it works well on Android Studio.
it come from
from ksp.
We use this logic in our tooling:
plugins.withId("com.google.devtools.ksp") {
the<BaseExtension>().variants.configureEach {
addJavaSourceFoldersToModel(layout.buildDirectory
.dir("generated/ksp/$name/kotlin").get().asFile)
}
}
having:
val BaseExtension.variants: DomainObjectSet<out BaseVariant>
get() = when (this) {
is AppExtension -> applicationVariants
is LibraryExtension -> libraryVariants
is TestExtension -> applicationVariants
else -> error("unsupported module type: $this")
}
from ksp.
This worked for us in an android library module.
androidComponents.onVariants {variant ->
kotlin.sourceSets.findByName(variant.name)?.kotlin?.srcDirs(
file("$buildDir/generated/ksp/${variant.name}/kotlin")
)
}
from ksp.
buildTypes {
getByName("debug") {
sourceSets {
getByName("main") {
java.srcDir(File("build/generated/ksp/debug/kotlin"))
}
}
}
getByName("release") {
sourceSets {
getByName("main") {
java.srcDir(File("build/generated/ksp/release/kotlin"))
}
}
}
}
I am using above script in build.gradle.kts and working as well for now.
from ksp.
Unfortunately, I haven't found it yet.
from ksp.
None of the above solutions work on Android Studio Flamingo | 2022.2.1 Canary 9
kotlin version: 1.7.20
ksp: 1.7.20-1.0.8
AGP: 8.0.0-alpha09
Gradle: 7.6
The solution that leinardi gave was working around canary 4 but I don't remember in which version it stopped.
from ksp.
The IDE extension, where KaptProjectResolverExtension resides, is bundled with the IntelliJ Kotlin plugin. Therefore that approach doesn't work for now.
from ksp.
Moving this to Q4 as it depends on upstreaming, which won't happen in Q3.
from ksp.
Deferring again to 2021Q1.
from ksp.
@eugene-krivobokov can you suggest correct solution for Android when using build variants? Thank you 🙏
from ksp.
@ting-yuan using 1.0.11 it looks like the following is still required sorry posted on the wrong issue
from ksp.
Related Issues (20)
- KSP2: implement KSPropertyDeclaration.findOverridee and Resolver.asMemberOf for java fields HOT 1
- KSP2: KSClassDeclaration.getSealedSubclasses for symbols defined in sources
- KSP2: Resolver.asMemberOf for local properties
- KSP2: Resolver.getSymbolsWithAnnotation misses top level callable declarations
- KSP2: Class values are missing class type in annotation values HOT 1
- KSP2: command line artifacts
- KSP2: embeddable artifacts
- KSP2: "Unresolved reference" in common code for entities annotated with SealedObjectInstances
- KSP warnings to raise a bug on Room even without Room HOT 2
- KSP 1.9.21-1.0.15 leaking memory and causing OOMs HOT 31
- KSP 1.9.21-1.0.15 leaking memory & causing OOMs for Buck HOT 1
- [KSP2] An operation is not implemented: Not yet implemented HOT 3
- KSP2: setSource method not found!
- Some strange problems occurred after using ksp, such as: resource id not found, no view found with id xxxx, or the content displayed by TextView is not normal. HOT 1
- NoClassDefFound in ksp.useKSP2=true mode HOT 1
- build fail when use kotlin 1.9.22 HOT 6
- e: java.lang.StackOverflowError when upgrade to AGP 8.2.0 and ksp HOT 1
- Class annotation values with `$` in name are `null` when used in Kotlin source HOT 1
- Unable to load class 'com.google.devtools.ksp.gradle.KspTaskJvm' HOT 1
- Issue when Compiling for iOS Kotlin Multiplatform for Latest Mvn Version 2.0.0-Beta2-1.0.16 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ksp.