Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to upgrade to Kotlin 1.9 #1445

Open
hantsy opened this issue Jul 11, 2023 · 19 comments
Open

Failed to upgrade to Kotlin 1.9 #1445

hantsy opened this issue Jul 11, 2023 · 19 comments

Comments

@hantsy
Copy link

hantsy commented Jul 11, 2023

I updated my project to Kotlin 1.9.0 and Gradle 8.2, and got the following build info.

A problem was found with the configuration of task ':kaptGenerateStubsKotlin' (type 'KaptGenerateStubsTask').
  - Gradle detected a problem with the following location: 'D:\FreelanceProjects\sami\etip-backend\build\generated\ksp\main\kotlin'.

    Reason: Task ':kaptGenerateStubsKotlin' uses this output of task ':kspKotlin' without declaring an explicit or implicit dependency. This can lead to incorrect results being produce
d, depending on what order the tasks are executed.

    Possible solutions:
      1. Declare task ':kspKotlin' as an input of ':kaptGenerateStubsKotlin'.
      2. Declare an explicit dependency on ':kspKotlin' from ':kaptGenerateStubsKotlin' using Task#dependsOn.

Add the following in the build.gradle.kts, did not resolve the issue.

tasks.named("kaptGenerateStubsKotlin"){
    dependsOn("kspKotlin")
}
@ting-yuan
Copy link
Collaborator

Would you mind sharing a small reproducible test case?

@hantsy
Copy link
Author

hantsy commented Jul 12, 2023

I am not sure if this is caused by KSP and Dataframe.

Add this to resolve our problem, our project used Kotlin Dataframe1 which used Ksp in Dataframe codegen plugin.

tasks.whenTaskAdded {
    if (name == "kaptGenerateStubsKotlin") {
        dependsOn("kspKotlin")
    }
    if (name == "kaptTestKotlin") {
        dependsOn("kspTestKotlin")
    }

//...
}

Footnotes

  1. https://github.com/Kotlin/dataframe

@Enaium
Copy link

Enaium commented Jul 19, 2023

+1 same here

@uladzislau-hryshechka
Copy link

+1 same here. We have multimodule android project. We use kapt and ksp at same time. Maybe you could provide a temporary workaround to fix this issue? Thanks in advance! @ting-yuan

@uladzislau-hryshechka
Copy link

uladzislau-hryshechka commented Jul 27, 2023

Temporary workaround which worked for us. If you use convention plugin:

pluginManager.withPlugin("com.google.devtools.ksp") {
        tasks.configureEach {
            if (name == "kaptGenerateStubsKotlin") {
                dependsOn("kspKotlin")
            }
            if (name == "kaptKotlin") {
                dependsOn("kspKotlin")
            }
        }
    }

If you don't use convention plugin, that works too. Add at the end of build.gradle.(kts) file:

tasks.configureEach {
        if (name == "kaptGenerateStubsKotlin") {
            dependsOn("kspKotlin")
        }
        if (name == "kaptKotlin") {
            dependsOn("kspKotlin")
        }
    }

@neetopia
Copy link
Contributor

@Enaium @uladzislau-hryshechka can you provide mode details on how your project is configured? From @hantsy 's case, it does seem like applying dataframe added a dependency since dataframe generates code with KSP that might be taken as input to KAPT.

@brentwatson
Copy link

+1 experiencing the same in our project. Same workaround resolved this for us.

@Enaium
Copy link

Enaium commented Jul 28, 2023

@Enaium @uladzislau-hryshechka can you provide mode details on how your project is configured? From @hantsy 's case, it does seem like applying dataframe added a dependency since dataframe generates code with KSP that might be taken as input to KAPT.

https://github.com/babyfish-ct/jimmer/tree/main/example/kotlin/jimmer-sql-kt

kotlin("jvm") version "1.9.0"
kotlin("kapt") version "1.9.0"
kotlin("plugin.spring") version "1.9.0"
id("com.google.devtools.ksp") version "1.9.0-1.0.12"

@uladzislau-hryshechka
Copy link

@Enaium @uladzislau-hryshechka can you provide mode details on how your project is configured? From @hantsy 's case, it does seem like applying dataframe added a dependency since dataframe generates code with KSP that might be taken as input to KAPT.

We have multimodule android project. Structure of this project:

- kotlin library module
- android library module
- app module  (which include all android and kotlin libraries)

Some modules could include ksp, kapt, both or nothing of that. It depends. Classical type of plugins which we use (for example android library):

plugins {
  id("base.android") - our convention plugin 
  id("kotlin-kapt")
  id("com.google.devtools.ksp")
}

GisoBartels added a commit to GisoBartels/kaster that referenced this issue Jul 28, 2023
@ZacSweers
Copy link
Contributor

I don't think this is a bug per-se, rather a side effect of kapt tasks no longer being eagerly initialized. I think the right solution would be for KSP to offer an API to add this dependency at the Gradle level.

Perhaps something like this? Or a gradle property?

ksp {
  makeKaptTasksDependOnKspTasks()
}

Where things get tricky are matching variants and KMP jvm source sets, but I think it'd be worthwhile to do.

@ting-yuan
Copy link
Collaborator

I guess some of the issues come from a previous workaround which lets IDE be aware of generated source:

kotlin {
	sourceSets.main {
		kotlin.srcDir("build/generated/ksp/main/kotlin")
	}
}

KSP has been doing this automatically, with dependencies correctly set up since 1.0.9. If you have this workaround in your build script, please try to remove it and see if the problem remains.

@Enaium
Copy link

Enaium commented Aug 4, 2023

I guess some of the issues come from a previous workaround which lets IDE be aware of generated source:

kotlin {
	sourceSets.main {
		kotlin.srcDir("build/generated/ksp/main/kotlin")
	}
}

KSP has been doing this automatically, with dependencies correctly set up since 1.0.9. If you have this workaround in your build script, please try to remove it and see if the problem remains.

But it still has problems after run the clean task

@ting-yuan
Copy link
Collaborator

Do you mean that, after removing that block / workaround and doing a clean build, the problem remains? If so, could you provide a sample project so that we can investigate?

@dimsuz
Copy link

dimsuz commented Sep 12, 2023

I don't have the srcDirs workaround mentioned above, but still got this error after upgrading to kotlin 1.9.10 and the corresponding ksp version.

@Enaium
Copy link

Enaium commented Oct 15, 2023

I solved the issue.

The kapt plugin must be declared after the ksp plugin.

plugins {
kotlin("jvm") version "1.9.0"
-kotlin("kapt") version "1.9.0"
id("com.google.devtools.ksp") version "1.9.0-1.0.12"
+kotlin("kapt") version "1.9.0"
}

kurbaniec added a commit to bee-produced/bee-built that referenced this issue Oct 18, 2023
…wrappers

Also fixed encountered issues:
* spring-projects/spring-security#13568
* gradle/gradle#20132
* google/ksp#1445

`BeeFetchedTest` now uses updated DGS generate client V2 API.
@shivam-gupta007
Copy link

I got this warning in upgrading to kotlin 1.9.10

ksp-1.8.10-1.0.9 is too old for kotlin-1.9.10. Please upgrade ksp or downgrade kotlin-gradle-plugin to 1.8.10.

is there any ksp version that is compatible with the kotlin 1.9.10

@neetopia
Copy link
Contributor

neetopia commented Dec 5, 2023

I got this warning in upgrading to kotlin 1.9.10

ksp-1.8.10-1.0.9 is too old for kotlin-1.9.10. Please upgrade ksp or downgrade kotlin-gradle-plugin to 1.8.10.

is there any ksp version that is compatible with the kotlin 1.9.10

you can try KSP 1.9.10-1.0.13

@shivam-gupta007
Copy link

Thanks @neetopia 🙌🙌

@Lysander
Copy link

Maybe my comment could help you: #963 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants