google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.83k stars 265 forks source link

[ksp] java.lang.IllegalArgumentException: this and base files have different roots #1079

Open mtrakal opened 2 years ago

mtrakal commented 2 years ago

KSP didn't respect gradle buildDir variable.

Using RAM disk (Z: drive) for build folders:

USER_HOME/.gradle/init.gradle

allprojects {
    buildDir="Z:/build/$group/$name/"
}

app/build.gradle

android {
    sourceSets {
        androidTest.assets.srcDirs += files("$projectDir/schemas".toString())

        main.kotlin.srcDirs += '$buildDir/generated/ksp/$name/kotlin/'
        test.kotlin.srcDirs += '$buildDir/generated/ksp/$name/kotlin/'
    }

    buildTypes {
       // https://github.com/InsertKoinIO/koin-annotations
        applicationVariants.all { variant ->
            variant.sourceSets.java.each {
                it.srcDirs += "$buildDir/generated/ksp/${variant.name}/kotlin/"
            }
        }
   }
}

But build failed with:

e: [ksp] java.lang.IllegalArgumentException: this and base files have different roots: Z:\build\ProjectX\app\generated\ksp\stagingDebug\java\cz\packagename\data\database\dao\UserOauthDao_Impl.java and D:\Projects\company\ProjectX\app.
    at kotlin.io.FilesKt__UtilsKt.toRelativeString(Utils.kt:117)
    at kotlin.io.FilesKt__UtilsKt.relativeTo(Utils.kt:128)
    at com.google.devtools.ksp.processing.impl.CodeGeneratorImpl.associate(CodeGeneratorImpl.kt:119)
    at com.google.devtools.ksp.processing.impl.CodeGeneratorImpl.createNewFile(CodeGeneratorImpl.kt:92)
    at androidx.room.compiler.processing.ksp.KspFiler.createNewFile(KspFiler.kt:106)
    at androidx.room.compiler.processing.ksp.KspFiler.write(KspFiler.kt:41)
    at androidx.room.compiler.processing.XFilerKt.writeTo(XFiler.kt:44)
    at androidx.room.compiler.processing.XFilerKt.writeTo$default(XFiler.kt:43)
    at androidx.room.writer.ClassWriter.write(ClassWriter.kt:75)
    at androidx.room.DatabaseProcessingStep.process(DatabaseProcessingStep.kt:111)
    at androidx.room.DatabaseProcessingStep.process(DatabaseProcessingStep.kt:42)
changfeng1050 commented 1 year ago

I have come across this problem too. And found no method to solve it. So I have to continue to use kapt. I prefer to use ramdisk other then ksp.

xBlackCat commented 1 year ago

Any progress on the issue?

mtrakal commented 6 months ago

@neetopia could you, please, set new milestone? 1.0.9 was already released (with only 56% complete) and this was not fixed... Still valid.