https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ksp
  • d

    Doni Winata

    01/31/2023, 7:42 AM
    does kapt will be deprecated in future and replace completly by ksp ?
    d
    • 2
    • 4
  • l

    Lukas Anda

    02/02/2023, 9:40 AM
    Hey there, after googling for a bit I didn’t find the answer to my question so I came here: Is there a way to identify a delegated property (by lazy, by inject()) etc by KSP ?
    e
    • 2
    • 1
  • t

    Tower Guidev2

    02/03/2023, 10:04 AM
    Hi how concerned should i be about this appearing in my android build output
    Configuration 'kspProductionDebugKotlinProcessorClasspath' was resolved during configuration time.
    This is a build performance and scalability issue.
    See <https://github.com/gradle/gradle/issues/2298>
    t
    • 2
    • 1
  • y

    Yang

    02/04/2023, 9:06 AM
    Just reported an kotlin IC issue here where incremental compilation of unit test fails when the processor takes code generated by another plugin as input. I’m not 100% sure it’s a KSP bug as it doesn’t happen with
    kotlin.incremental=false
    so please let me know if I should report on YouTrack instead.
    • 1
    • 1
  • b

    Big Chungus

    02/06/2023, 2:22 PM
    I think ksp has regressed with the latest release. Is there a workaround for this? https://github.com/google/ksp/issues/367#issuecomment-1416879144
    r
    • 2
    • 1
  • a

    Ahmed na

    02/06/2023, 11:30 PM
    Hi , hope i'm at the right channel Using
    KSClassDeclaration
    for type
    ClassKind.ENUM_CLASS
    is it possible to get the names of the enums ?
    j
    • 2
    • 2
  • j

    josel

    02/07/2023, 5:08 AM
    Hi, in a multi-module kotlin multiplatform project, if you set a processor with kspCommonMainMetadata in one module, ksp fails if asked to resolve any type that is declared in any of the other local modules.
    • 1
    • 3
  • j

    jean

    02/08/2023, 9:04 AM
    How do I add a dependency to the module
    generatedByKspCommonMainKotlinMetadata
    ? When I use the automatic import from IntelliJ, it adds
    implementation(project(mapOf("path" to ":")))
    which doesn’t work
  • t

    trevjones

    02/10/2023, 6:30 PM
    FYI: I found an interesting interaction loop between KSP and NAPT https://github.com/google/ksp/issues/1321 Reproduction of it is in a PR against the NAPT project. Blocks me from bumping kotlin/ksp up to latest and I can't drop NAPT until dagger ships the ksp processor 😕
    z
    • 2
    • 1
  • e

    elye

    02/13/2023, 12:46 PM
    Hi All 👋 , how do I print a log out for debugging purpose for KSP? https://stackoverflow.com/questions/75436055/how-to-print-a-log-in-kotlin-ksp-processor
    f
    • 2
    • 3
  • z

    Zac Sweers

    02/14/2023, 6:27 AM
    FYI, it looks like AGP/Gradle 8 have a bug around KSP that fails builds in gradle 8. https://issuetracker.google.com/issues/269089135
    d
    • 2
    • 2
  • s

    Slackbot

    02/20/2023, 6:01 PM
    This message was deleted.
    d
    • 2
    • 1
  • j

    Jerv Norsk

    02/21/2023, 10:28 AM
    Hello, there is a way to use KSP with Lombok and Mapstruct?
    b
    j
    • 3
    • 4
  • t

    Tristan

    02/21/2023, 5:15 PM
    Hello, Is it possible to use KSP to replicate what is done by derive in Rust? With editor support. For instance, with
    data class
    , compiler will generate some standard code. With
    suspend
    it will perform some transformation as well. Same with
    inline
    . That’s for keywords, but there are also
    @Compose
    for Jetpack Compose and
    @Serializable
    for Kotlinx.serialization. The last one is really cool. It will generate all of what is needed for de/serialization, and methods such as
    Json.decodeFromString<Person>(string)
    are showing errors right away in the IDE if Person is not annotated with
    Serializable
    . This does not use KSP (I think), but a compiler plugin. Would KSP be able to reproduce the same experience before execution?
    import com.me.WithMyFeature
    import com.me.useFeature
    
    @WithMyFeature
    class Dog
    
    class Person
    
    val dog = Dog()
    val person = Person()
    
    dog.useFeature() // No issue
    
    person.useFeature() // Issue
    I saw this kind of solution, but that would only work at runtime :/
    @Suppress("UNUSED_PARAMETER")
    fun Any.useFeature() {
      throw NotImplementedError("missing implementation")
    }
    c
    j
    • 3
    • 3
  • v

    Vladimir Tagakov

    02/22/2023, 2:44 AM
    Hi! We moved from javac based annotation processors to everything written with KSP and we are seeing ridiculously big difference in memory footprint. At the first glance it seems like a memory leak in either KSP or kotlinc. Our processor doesn’t have any fields, top-level fields, objects, companion objects or anything static involved. Everything we reference has a scope of
    process
    function and should be freed after exiting. So it is highly unlikely that there is a memory leak on our side 😞 We are comparing Kotlin + javac annotation processing with Kotlin + KSP annotation processing and the difference in peak memory consumption for the whole build is: • For Kotlin+Javac: 39.5 Gb • For Kotlin+KSP: 62.5 Gb Both setups are using
    Bazel
    workers, to verify that it is a memory leak we changed strategy to
    local
    (which is basically starts new instance of kotlinc for every module instead of using long running daemons) and the memory usage felt back to normal values (still slightly more with KSP but tolerable) Can someone help me with triaging this issue and give me a clue how to run some diagnostics so I’ll be able to create a proper bug report? Was fixed by: https://github.com/google/ksp/pull/1067
    y
    j
    • 3
    • 10
  • a

    agrosner

    02/23/2023, 1:49 PM
    It seems that there is not going to be support for databinding with ksp. Is there a community effort to make a ksp compliant version? We have a large app with a few modules that are in databinding and won’t be redone or removed for quite some time. We want to use Anvil for its ability to skip kapt and generate dagger factories purely through kotlinc. However, we lose that ability to do (and must go back on KAPT) when our modules include the databinding compiler (and actually use it more than converting to viewbinding).
    w
    y
    • 3
    • 6
  • v

    Vladimir Tagakov

    02/24/2023, 1:38 AM
    I’m profiling my KSP processor and seeing that KSP spends a lot of time visiting classes’ props and funs declarations. The annotation I’m using is only applicable to types, so it is waste of time to scan props and funs. I understand that current processor’s API doesn’t help to avoid that since there is no way to know which annotations are used by the processor and configure
    CollectAnnotatedSymbolsVisitor
    appropriately. But maybe you think it is a good idea to introduce an
    annotations()
    fun like javac processors have and infer what exactly should be visited with given set of KSP processors and all annotations they aim to use?
    j
    • 2
    • 10
  • t

    trevjones

    02/24/2023, 5:26 PM
    KSP 2 landed in the EAP channel today! (😉 have a great weekend everybody) https://store.steampowered.com/app/954850/Kerbal_Space_Program_2/
    z
    • 2
    • 1
  • u

    Uli Bubenheimer

    02/25/2023, 8:41 PM
    What approach do folks here use to insure against processor crashes due to malformed annotations? ksp runs before kotlinCompile, so annotations may be bad. This can trigger crash in processor without any indication to user about what the malformed element is, and compiler won't get to run to show the offending element, either. Many of the examples below cause various exceptions in ksp while trying to access the annotation and its value.
    @MyIntThing(1) // correct
    @MyIntThing(1,2) // no
    @MyIntThing("nope")
    @MyIntThing(1) @MyIntThing(2) //no, it's not repeatable
    @MyIntThing(1L) // no, really
    y
    • 2
    • 23
  • a

    Ahmed na

    02/28/2023, 12:12 AM
    Hi Can we use generated classes in original annotated class ?
    @MyAnnotatoin
    data class A(){
       fun b(): MyAnnotatoinGeneratedClass {
           return MyAnnotatoinGeneratedClass()
       }
    }
    where
    MyAnnotatoinGeneratedClass
    is a class that was generated by
    @MyAnnotation
    Ofc i'm getting not resolved right now
    b
    y
    j
    • 4
    • 13
  • e

    elye

    03/01/2023, 9:23 AM
    Hi All, If I want to see the Info log info for KSP debugging, where can I set the
    --verbose
    mode through IntelliJ or Android Studio? I post the question in https://stackoverflow.com/questions/75601653/how-to-set-verbose-in-intellij-android-studio-for-ksp-debugging-purposes too. Thanks 🙏
    j
    • 2
    • 2
  • r

    Richard Glen

    03/02/2023, 5:54 AM
    Anyone here who can suggest how to use ksp in a kscript? Tho, tbh, I'm thinking of just migrating this script to be an executable fatjar instead 😒miling_face_with_tear:
    e
    j
    • 3
    • 2
  • j

    jean

    03/03/2023, 10:33 AM
    Is it possible to get the value of a property with KSP?
    @MyAnnotation
    class MyConfig : Config {
        override val configField1: String = "a"
        override val configField2: String = "b"
    }
    Is it possible to get “a” out of ksClassDeclaration?
    g
    j
    • 3
    • 7
  • d

    Derek Ellis

    03/03/2023, 9:18 PM
    Are there any patterns for generating files from a symbol processor that aren't code/resource files while still maintaining support for incremental processing? e.g. I want to write a report to some path so that I can use it in later gradle tasks
    j
    • 2
    • 3
  • c

    Charlie Tapping

    03/06/2023, 5:27 PM
    If I have an annotated class Foo<T>, and I use the symbol information for the generic type T to create a file, should I tag the file spec with the originatingFile as T or Foo? What if multiple Ts make up a file, should all of them be tagged as the originating file? Any help is much appreciated
    j
    • 2
    • 6
  • g

    Gaurav Dhingra

    03/07/2023, 10:26 AM
    I've a multi-module project using KSP version 1.8.10-1.0.9 and it would be helpful if someone can help me with disabling the task of code-generation in the tests sub-directory of the build directory. This is roughly the structure of the project:
    myProject
        - api
        - engine
        - methods
            - build.gradle.kts
    dependencies { implementation(project(":engine")) implementation(project(":methodsProcessor")) testImplementation(kotlin("test")) testImplementation(testFixtures(project(":engine"))) testImplementation("org.junit.jupiter:junit-jupiter-params:5.8.2") ksp(project(":methodsProcessor")) }
    - build
                - generated
                    - ksp
                        - main
                            - kotlin
                                - methods
                                    - PublicMethods.kt
    
                        - test   ##  I don't want this directory to be created at all
                            - kotlin
                                - methods
                                    - PublicMethods.kt
        - methodsProcessor
            - build.gradle.kts (contents below)
    dependencies { implementation(libs.ksp.api) }
    - src.main.kotlin.processor.MethodsProcessor
                ## this file has a SymbolProcessor which creates a new file (PublicMethods.kt) in
                ## `methods/build/generated/ksp/main/kotlin/methods` &
                ## `methods/build/generated/ksp/test/kotlin/methods` (THIS I would like not to be created)
        - build.gradle.kts
        - settings.gradle.kts
    rootProject.name = "myProject" include("engine") include("methods") include("api") include("methodsProcessor") val kotlinVersion: String by settings val kspVersion: String by settings pluginManagement { plugins { // For some reason the global variables are not accessible here val kotlinVersion: String by settings val kspVersion: String by settings kotlin("jvm") version kotlinVersion kotlin("plugin.jpa") version kotlinVersion kotlin("plugin.spring") version kotlinVersion id("com.google.devtools.ksp") version kspVersion } } dependencyResolutionManagement { repositories { mavenCentral() } versionCatalogs { create("libs") { library("ksp-api", "com.google.devtools.ksp😒ymbol-processing-api:$kspVersion") } } }
    ```
    
    When I run `./gradlew build` for my project, the output on the terminal looks like:
    ```> Task :api:openApiGenerate
    ################################################################################
    # Thanks for using OpenAPI Generator.                                          #
    # Please consider donation to help us maintain this project :pray:                 #
    # <https://opencollective.com/openapi_generator/donate>                          #
    ################################################################################
    Successfully generated code to /Users/gxyd/projects/solver-engine/api/build/generated-src/openapi
    
    > Task :methods:kspKotlin
    w: [ksp] hello world
    
    Daemon will be stopped at the end of the build after running out of JVM memory
    
    > Task :methods:kspTestKotlin
    w: [ksp] hello world
    So, the second task that you see, i.e.
    :methods:kspTestKotlin
    is something I don't to it to run. I've already tried having the below configuration in `methods.build.gradle.kts`:
    ksp {
        tasks.named("kspTestKotlin") {
            enabled = false
        }
    }
    which raises the error saying, there is no task named "kspTestKotlin", while building my project.
  • z

    Zac Sweers

    03/08/2023, 12:19 AM
    Any chance of a bugfix release with the fix for resolving dependencies at configuration-time? It's quite a noisy log on top of the performance penalty
    j
    • 2
    • 4
  • c

    Charlie Tapping

    03/08/2023, 12:31 PM
    I have a test which asserts that ksp compilation fails when a certain invariant is broken. The test passes, but the failure I log through to ksp is always printed to stdout. Is there anyway of preventing this? It’s fine for me but for other members of my team they may believe this is a real error when reading CI logs rather than a situation I’m simulating in test.
    d
    • 2
    • 1
  • r

    Rohan Maity

    03/08/2023, 4:35 PM
    Is there a deepCopy KSP available? I was thinking to make one 🤓
    g
    • 2
    • 4
  • l

    leandro

    03/09/2023, 11:12 AM
    We have KSP in our project and to have its generated files be picked up by Android tasks, we had to declare on our build.gradle inside `android{}`:
    sourceSets {
        debug.java.srcDirs += 'build/generated/ksp/debug/kotlin'
        release.java.srcDirs += 'build/generated/ksp/release/kotlin'
        testDebug.java.srcDirs += 'build/generated/ksp/debugUnitTest/kotlin'
        androidTestDebug.java.srcDirs += 'build/generated/ksp/debugAndroidTest/kotlin'
      }
    This was added while we were using Kotlin 1.7.x... on our tests using Kotlin 1.8.10, this doesnt seem to be necessary anymore, and I am trying to confirm if this was fixed? Thanks
    g
    j
    • 3
    • 4
Powered by Linen
Title
l

leandro

03/09/2023, 11:12 AM
We have KSP in our project and to have its generated files be picked up by Android tasks, we had to declare on our build.gradle inside `android{}`:
sourceSets {
    debug.java.srcDirs += 'build/generated/ksp/debug/kotlin'
    release.java.srcDirs += 'build/generated/ksp/release/kotlin'
    testDebug.java.srcDirs += 'build/generated/ksp/debugUnitTest/kotlin'
    androidTestDebug.java.srcDirs += 'build/generated/ksp/debugAndroidTest/kotlin'
  }
This was added while we were using Kotlin 1.7.x... on our tests using Kotlin 1.8.10, this doesnt seem to be necessary anymore, and I am trying to confirm if this was fixed? Thanks
g

glureau

03/09/2023, 11:26 AM
I think this trick was for the IDE to be aware. If the doc is right, it's still required for IDE, and maybe your IDE works because of some IDE cached files? Have you tried to invalidate your IDE cache and/or remove the .idea and then reload your project to see if it's still alright for IDE without the sourceSets trick?
l

leandro

03/09/2023, 11:43 AM
Hey glureau, I did indeed invalidate the caches and removed my .idea directory, and things just work now. You're right that it could be the idea, i know it was not working on Dolphin, but on EE and Giraffe things seem to be fine
j

Jiaxiang

03/09/2023, 6:49 PM
Actually, the doc is outdated and we should update it, since latest KSP 1.0.9, it should be already included for IDE to index.
l

leandro

03/09/2023, 9:17 PM
Amazing, thanks for the confirmation!
View count: 11