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
  • v

    Vladimir Tagakov

    08/03/2022, 7:10 AM
    //Module A
    public class MyJavaClass {
      public @interface MyAnnotation {}
    }
    
    //Module B with KSP Processor
    class MyKotlinClass(@MyJavaClass.MyAnnotation val myProp: Any)
    Hi! In my KSP Processor I’m trying to resolve
    KSTypeReference
    of annotation type
    MyJavaClass.MyAnnotation
    which I face during analysis of `MyKotlinClass`’s constructor and for some reason it could not be resolved (
    KSType#isError
    returns true). If I move
    MyAnnotation
    to the top-level everything works fine. I am not sure how I can debug this issue, any ideas? =\
    j
    • 2
    • 10
  • v

    Vaios Tsitsonis

    08/04/2022, 9:24 AM
    Hello! We released a small library for converting enums to primitives and vice versa with the help of KSP. If someone wants to use it or give a feedback here is the link https://github.com/bluegroundltd/enum-convertible
    p
    • 2
    • 1
  • j

    juliocbcotta

    08/04/2022, 9:34 AM
    hey, I noticed some behaviour when running gradle profiler benchmark that I am not sure if it is the desired one. kotlin daemon memory usage and live threads keep increasing when ksp is enabled. The only library using ksp in the project is room and I run the benchmark 50 times to check if the memory usage would stabilise at some point as I am just compiling the app over and over (without changes in the code) and as you can see by the image below the memory usage keeps increasing for each iteration of the benchmark. These charts are from a sample project that I can share and the GC starts to be noticeable around the 25th compilation for this project, but much earlier for other configs/projects. I would expect the amount of memory used to be stable around the 4th or 5th compilation. Is it normal? Should I open an issue at ksp repo ? room issue tracker? jetbrains issue tracker?
    j
    t
    • 3
    • 4
  • s

    Stylianos Gakis

    08/04/2022, 12:18 PM
    New to KSP here so I got a question. I am building something in KSP to generate some code according to some annotations. I got the KSP code in a separate module called
    :kspProcessors
    inside the project, and I am importing it into my module (let’s call it
    :app
    ) where I want the code generated with
    add("kspJs", project(":kspProcessors"))
    ,
    add("kspAndroid", project(":kspProcessors"))
    and
    add("kspIosX64", project(":kspProcessors"))
    . Thing is, inside my KSP, code, it’d be very convenient to have access to the classes that exist inside my
    :app
    module, to more easily reference them in the code I generate. But would I not then introduce a circular dependency if
    :kspProcessors
    was depending on
    :app
    with
    implementation(project(":app"))
    and had
    :app
    depend on the ksp module as I am describing above? Would I need to keep the KSP code inside the same module? Maybe there’s no circular dep if one depends on the other using
    implementation
    and the other using
    ksp
    ? I do not know if I am wording my question as well as I could’ve since I am totally not familiar with how to work with KSP in general, so please ask clarifying questions if I can make something more understandable.
    w
    • 2
    • 4
  • s

    Stylianos Gakis

    08/04/2022, 4:17 PM
    I’m having an annotation that looks like this:
    annotation class ComposeRenderer(
      val forComponent: KClass<out Component>,
    )
    I can’t figure out if it’s be possible to get in some way what the KClass would be to get it’s name, package and if it has any generics, and I am having a hard time looking into the documentation myself in order to help myself basically. And the questions existing online on SOF or whatever are quite sparse for KSP. Is there some place where people tend to go when they have KSP questions that I should be aware of?
    m
    j
    d
    • 4
    • 4
  • o

    Ovsyannikov Alexey

    08/05/2022, 7:25 AM
    Hello everybody 🙂 is there in the KSP opportunity to get all subtypes (subclasses/subinterfaces) for some
    KSCLassDeclaration
    in case if that declaration is no sealed?
    j
    • 2
    • 1
  • j

    Joost Klitsie

    08/08/2022, 9:13 AM
    Hello my people! We run an OWASP dependency analyzer. According to this analyzer, the KSP plugin and the room-ksp has a vulnerability:
    room-compiler-processing-2.4.3.jar (pkg:maven/androidx.room/room-compiler-processing@2.4.3, cpe:2.3:a:processing:processing:2.4.3:*:*:*:*:*:*:*) : CVE-2018-1000840
    symbol-processing-1.7.10-1.0.6.jar (pkg:maven/com.google.devtools.ksp/symbol-processing@1.7.10-1.0.6, cpe:2.3:a:processing:processing:1.7.10.1:*:*:*:*:*:*:*) : CVE-2018-1000840
    symbol-processing-api-1.7.10-1.0.6.jar (pkg:maven/com.google.devtools.ksp/symbol-processing-api@1.7.10-1.0.6, cpe:2.3:a:processing:processing:1.7.10.1:*:*:*:*:*:*:*) : CVE-2018-1000840
    Am I correct that we can safely ignore this? I assume the generated code will not be affected by this. (we are building an Android application so we care mostly about runtime safety)
    j
    • 2
    • 1
  • s

    Slackbot

    08/11/2022, 1:59 PM
    This message was deleted.
    z
    • 2
    • 1
  • s

    SrSouza

    08/11/2022, 9:18 PM
    Did anyone use or anyone knows if KSP for processing Kotlin scripting source files?
    j
    • 2
    • 1
  • j

    jean

    08/12/2022, 9:24 AM
    How should I proceed to get all the properties from all the classes annotated with a given annotation and create an enum out of them? The example I followed so far deals with one annotated class at a time, is it possible to create a file when processing the first file and add values to it in the following classes?
    g
    j
    • 3
    • 9
  • m

    Michal Klimczak

    08/14/2022, 3:15 PM
    How are ksp gradle tasks included into other assemble tasks? My library relies on kspCommonMainMetadata being run. For me it's run for KMM's embedAndSignAppleFrameworkForXcode but for another person it's not. How can I debug such an issue?
    j
    • 2
    • 11
  • z

    Zac Sweers

    08/16/2022, 8:15 PM
    I see warnings like this from JavaCompile tasks later, would it be worth filing an issue to not generate empty dirs?
    file or directory '/Users/zacsweers/dev/slack/slack-android-ng/app/build/generated/ksp/internalDebugAndroidTest/classes', not found
    Transforming core-for-system-modules.jar with JdkImageTransform
    Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.
    Compiling with toolchain '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home'.
    file or directory '/Users/zacsweers/dev/slack/slack-android-ng/app/src/androidTestDebug/java', not found
    file or directory '/Users/zacsweers/dev/slack/slack-android-ng/app/build/generated/ksp/internalDebugAndroidTest/java', not found
    file or directory '/Users/zacsweers/dev/slack/slack-android-ng/app/build/generated/ksp/internalDebugAndroidTest/java', not found
    t
    • 2
    • 2
  • a

    Aditya Kurkure

    08/18/2022, 8:31 AM
    While using KSP with multipaltform my project cannot resolve classes inside the
    kspcache
    however it works perfectly fine on the first run when the classes are located at
    build>generated>ksp
    any idea why this happens and what the fix might be?
  • j

    Jintin

    08/23/2022, 12:57 AM
    A simple introduction and example of KSP, hope it can help any of you who are new to it. Feel free to comment if you have any suggestion. Thanks! https://medium.com/google-developer-experts/ksp-for-code-generation-dfd2073a6635
  • g

    Grégory Lureau

    08/25/2022, 10:00 AM
    When I enable KSP on a KMP project (Android/JS/...) and I run only
    compileTestKotlinJs
    it somehow triggers the task
    kspReleaseUnitTestKotlinAndroid
    . Any idea why it's linked? Is it an expected behavior?
    t
    m
    • 3
    • 9
  • j

    jean

    08/25/2022, 7:55 PM
    Is there a better way to check that the class of each element of a list is annotated?
    return (argument as Array<KClass<*>>)
        .toList()
        .all {
            resolver.getClassDeclarationByName(it::class.java.simpleName)
                ?.filterAnnotations<CrossViewEvent>()
                ?.toList()
                ?.isNotEmpty() ?: false
        }
    is it possible to convert a
    KClass
    to a
    KSType
    without using the resolver?
    d
    t
    • 3
    • 5
  • p

    PHondogo

    08/25/2022, 9:03 PM
    Hello! Does KSP have possibility to iterate through all symbols in all module dependencies?
    j
    j
    • 3
    • 3
  • j

    Ji Sungbin

    08/29/2022, 1:09 AM
    Is it possible to create a file in an external folder other than the build folder through KSP? I tried this but it didn’t work. (Using the
    java.io.File
    package)
    j
    • 2
    • 2
  • v

    Vladimir Tagakov

    08/29/2022, 10:26 PM
    Hi! I’m looking at the weird issue right now. I have a module with mixed kotlin\java code and in this module I have two java classes in two different packages. They both have the same annotation and they both passing a nested class to annotation’s
    Class<?>
    argument. And for some reason for one class KSP resolves class type passed to the argument successfully and for another class KSP returns ERROR TYPE. It looks super weird since both annotated classes very similar, both have the same visibility and implement same interfaces. The only difference is the package. Class passed to a
    Class<?>
    argument in both cases is being nested inside annotated class itself. I’m confused and not sure how to even approach debugging here =\
    t
    • 2
    • 2
  • s

    Shreyash Saitwal

    09/01/2022, 4:48 PM
    Hi there, is it possible to get the name of the constants an enum declares? This isn't possible with the traditional Java annotation processing but I was curious if it's something KSP might support.
    j
    b
    • 3
    • 28
  • j

    juliocbcotta

    09/05/2022, 2:52 PM
    Do we have any plans for the next release of ksp for the current stable version of kotlin?
    t
    j
    j
    • 4
    • 6
  • j

    juliocbcotta

    09/08/2022, 10:41 AM
    Has anyone tried to update AndroidManifest.xml using ksp ? Any github repo with it?
    j
    • 2
    • 2
  • o

    Odin

    09/10/2022, 6:47 PM
    Hi, this might be me that has missed something fundamentally about KSP, but I was wondering; Is there a way to get the annotation of an annotation that is in a different module than the element that is annotated? 🤔 I can get the base annotation from the
    XRoundEnv.getElementAnnotatedBy
    if I know the qualifiedName of the annotation in question. However, if I use the typeName of the annotation that I get from
    XRoundEnv.getElementAnnotatedBy
    to fetch the annotation that the first annotation is annotated with, it only works if they are in the same module. Does anyone know if this is possible? 😄 Is it not working because I use the typeName form the first annotation?
    y
    • 2
    • 2
  • e

    evant

    09/13/2022, 12:12 AM
    I'm running into an issue where
    declaration.getAllFunctions()
    is not picking up functions though a type generated in a previous round, ie: If I have:
    interface Source { fun targetFun() {} }
    interface Generated : Source // this is generated in round 1
    interface Target : Generated // this is processed in round 2
    then
    declaration.getAllFunctions()
    won't include
    targetFun()
    interestingly enough walking up to the interface manually does work
    ((declaration.superTypes.first().resolve().declaration as KSClassDeclaration).superTypes.first().resolve().declaration as KSClassDeclaration).getDeclaredFunctions()
    t
    • 2
    • 2
  • t

    TheDukerChip

    09/13/2022, 4:19 AM
    I am getting
    UnknownPluginException
    for KSP
    org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.google.devtools.ksp', version: '1.7.10-1.0.6'] was not found in any of the following sources:
    
    - Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
    - Plugin Repositories (could not resolve plugin artifact 'com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:1.7.10-1.0.6')
    Following is the configuration added in my android project
    app/build.gradle
    plugins {
        id("com.android.application")
        id("kotlin-android")
        id 'com.google.devtools.ksp' version("1.7.10-1.0.6")
    }
    
    dependencies {
        """
        def room_version = "2.4.3"
        implementation "androidx.room:room-runtime:$room_version"
        ksp "androidx.room:room-compiler:$room_version"
    }
    j
    • 2
    • 1
  • s

    Simon

    09/13/2022, 3:45 PM
    Hi there, it looks like KSP supports only
    KSClassDeclaration
    ,
    KSFunctionDeclaration
    and
    KSPropertyDeclaration
    . Do you know whether there is a plan to also support annotations with
    @Target(AnnotationTarget.EXPRESSION)
    ? Thanks!
    j
    • 2
    • 1
  • v

    Vladimir Tagakov

    09/14/2022, 8:40 PM
    I think there is a bug In KSP’s method
    com.google.devtools.ksp.UtilsKt#isVisibleFrom
    . When it looks at protected visibility it treats it as visible if it is in the same package with a class passed to
    isVisibleFrom
    it works for java but doesn’t work for kotlin, because in kotlin protected is only accessible from the class inheritors.
    • 1
    • 1
  • s

    spierce7

    09/22/2022, 1:24 PM
    Can KSP see the code from dependency modules, or libraries? Or can it only alter the current module’s code?
    j
    b
    • 3
    • 3
  • c

    Christopher Porto

    09/23/2022, 11:38 PM
    Hello, I have an annotation that takes a KClass, I wanted to access information of that class in processor but it's not in class path, was wondering if theres a way to work around this? Do I have no choice but to provide the class information I need in annotation instead
    j
    j
    d
    • 4
    • 10
  • j

    jean

    09/24/2022, 8:27 AM
    I’m trying to access my generated code from unit tests so I added this
    sourceSets.commonMain {
        kotlin.srcDir("$buildDir/generated/ksp/commonMain/kotlin/")
    }
    sourceSets.commonTest {
        kotlin.srcDir("$buildDir/generated/ksp/commonMain/kotlin/")
    }
    But I still get a
    Source file or directory not found
    . What should I do to fix that?
    t
    • 2
    • 4
Powered by Linen
Title
j

jean

09/24/2022, 8:27 AM
I’m trying to access my generated code from unit tests so I added this
sourceSets.commonMain {
    kotlin.srcDir("$buildDir/generated/ksp/commonMain/kotlin/")
}
sourceSets.commonTest {
    kotlin.srcDir("$buildDir/generated/ksp/commonMain/kotlin/")
}
But I still get a
Source file or directory not found
. What should I do to fix that?
If I replace
$buildDir
with
build
, I then get this
Task :example:linkDebugTestIosX64 FAILED
...
Compilation failed: IrClassPublicSymbolImpl for com.jeantuffier.statemachine/MyClass|null[0] is already bound: CLASS CLASS MyClass modality:SEALED visibility:public superTypes:[kotlin.Any]

 * Source files:
 * Compiler version info: Konan: 1.7.10 / Kotlin: 1.7.20
 * Output kind: PROGRAM
I can actually run my unit tests mannually on the jvm and it works. But the error comes again when I try to run the unit tests on ios.
t

Ting-Yuan Huang

09/29/2022, 4:40 PM
Adding a source from main source set to the test source set might cause multiple-definition issues: one from the source, and the other from the dependency. Do you really need to access the generated code? If you know the class names,
Resolver.getClassDeclarationByName
returns the compiled classes.
j

jean

09/29/2022, 6:26 PM
That seems to solve my issue, thanks!
View count: 39