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

    simon.vergauwen

    12/31/2021, 8:48 AM
    Hey everyone, Does anyone know if it’s possible to use KSP in MPP testing? I’m using
    add("kspMetadata", dependencyNotation)
    and all targets
    add("kspTargetTest", dependencyNotation)
    but it doesn’t generate any code for
    commonTest
    . It generated it for all platforms. Should I manually also generate
    expect/actual
    ? Is there an example of this anywhere?
    e
    • 2
    • 1
  • r

    rkeazor

    01/04/2022, 2:57 AM
    is it possible to use a debugger on your Symbol Processor?
    g
    • 2
    • 2
  • d

    dvdandroid

    01/04/2022, 8:04 PM
    is it possible to get a ksclassdeclaration by the name of a class (without its package name)?
    Resolver.getClassDeclarationByName
    requires a fully qualified name i need to reference a class compiled in another module with the same processor (and in the same classpath) (=> i'd like to cache all generated files by the processor even if in different compilation units)
    j
    • 2
    • 1
  • j

    jameskleeh

    01/04/2022, 8:27 PM
    I have a module with a processor in src/main. I’d like the classes in src/test to be visited by the processor. Is that possible and if so, what configuration would I need for it to work?
    y
    • 2
    • 4
  • d

    diego-gomez-olvera

    01/05/2022, 3:33 PM
    hello! I am looking for a way to rename/obfuscate certain property names, and I was wondering if KSP could help with that, until I saw
    The following are not goals of KSP:
    • Modifying source code.
    so I guess that it is not possible. Is that right?
    p
    b
    • 3
    • 3
  • z

    Zac Sweers

    01/05/2022, 6:32 PM
    when working with a sealed class (where sealedSubclasses are accessible from the sealed parent), would a processor that cares about annotations (and their entry values) on subclasses be aggregating in this case? Or still isolating if everything goes through the sealed parent initially?
    y
    t
    • 3
    • 4
  • d

    Dutch

    01/05/2022, 8:15 PM
    Hello everyone, is it possible to retrieve the default value (initializer) from a KSPropertyDeclaration? If so, how?
    j
    • 2
    • 7
  • z

    Zac Sweers

    01/06/2022, 7:59 PM
    Does KSP effectively block other analysishandlerextension plugins from running in its KspTask?
    > Task :lib.bookmarks:kspReleaseKotlin FAILED
    e: java.lang.RuntimeException: Duplicate registration for EP 'org.jetbrains.kotlin.com.intellij.psi.treeChangeListener': first in FakeIdForTests, second in FakeIdForTests
            at org.jetbrains.kotlin.com.intellij.openapi.components.ComponentManager.createError(ComponentManager.java:167)
            at org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.checkThatPointNotDuplicated(ExtensionsAreaImpl.java:235)
            at org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.registerExtensionPoint(ExtensionsAreaImpl.java:240)
            at org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.doRegisterExtensionPoint(ExtensionsAreaImpl.java:210)
            at org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.doRegisterExtensionPoint(ExtensionsAreaImpl.java:189)
            at org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.doRegisterExtensionPoint(ExtensionsAreaImpl.java:183)
            at org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.registerExtensionPoint(ExtensionsAreaImpl.java:160)
            at dev.zacsweers.moshix.ir.compiler.proguardgen.ProguardRuleGenerationExtension.doAnalysis(ProguardRuleGenerationExtension.kt:59)
    t
    • 2
    • 2
  • a

    atlantis210

    01/07/2022, 2:12 PM
    Hi guys, I have a dumb question: is it possible to add logs in the BuilderProcessor ? I tried println, print and even using the environment.logger, but I don't know where are going the logs... ? Also, I'm trying to get params from an annotation
    annotation class Dummy(val integer: Int = 0, val string: String = "")
    but cannot seem to retrieve arguments when passed in
    @Dummy(integer = 1, string = "hello")
    . I thought using
    visitAnnotation
    will do the trick but somehow the code doesn't get inside... I think that this is the `process()`method that is not done right but not sure how to do it...
    override fun process(resolver: Resolver): List<KSAnnotated> {
        val symbols = resolver.getSymbolsWithAnnotation("com.example.annotation.Dummy")
        print("symbol + $symbols")
        val list = symbols.filter { !it.validate() }.toList()
        symbols
            .filter { (it is KSAnnotation || it is KSClassDeclaration) && it.validate() }
            .forEach { it.accept(BuilderVisitor(), Unit) }
        return list
    }
    j
    • 2
    • 11
  • g

    Grégory Lureau

    01/12/2022, 9:43 AM
    Hello! I'm processing an interface (with generics) from another module, this interface extends another interface (also with generics), I can get the properties & functions from the super but
    superTypes
    and
    getAllSuperTypes()
    returns nothing. Is it an expected/known behavior? (1.6.0-1.0.2)
    j
    d
    • 3
    • 6
  • t

    Thomas

    01/12/2022, 1:43 PM
    Can KSP be used to generate Kotlin code from some files in resources? I am looking for something similar to how the Android R class is generated from resources. Can KSP be used for this?
    🇳🇴 2
    e
    j
    • 3
    • 3
  • y

    yigit

    01/14/2022, 2:01 AM
    Also, often times, annotations module is also not an Android module so the processor can depend on it
    d
    • 2
    • 3
  • j

    jameskleeh

    01/14/2022, 4:23 PM
    Is there an implementation of
    KSVisitor
    that actually traverses the object?
    t
    • 2
    • 3
  • d

    Dutch

    01/17/2022, 1:00 AM
    My generated sources can be found under
    builddir/generated/*
    but arent usable inside my project. Intellij does not recognize the packages/classes. Trying to reference to them using
    Class.forName
    during runtime does also not work. Generated classes from Android Room (kapt) are usable.. What am I missing?
    e
    • 2
    • 5
  • p

    philglass

    01/21/2022, 9:56 AM
    I’ve been migrating our internal annotation processors to KSP and I’m having all sorts of trouble getting the aggregating one to work correctly incrementally. They’re a layer on top of Dagger that supports broadly similar things to Hilt or Anvil. It’s multi-round and uses symbols from both the classpath (via
    getDeclarationsFromPackage
    ) and the current compilation unit, but is otherwise pretty simple. I reproduced a simplified, standlone version as a KSP integration test here - you can run it with
    ./gradlew integration-tests:test --tests 'com.google.devtools.ksp.test.BrokenIncrementalIT.*'
    Any idea where I’m going wrong? Or am I running into bugs in KSP?
    👀 1
    t
    • 2
    • 3
  • j

    jameskleeh

    01/21/2022, 8:45 PM
    Hey folks I’m having issues with annotations on annotation members
    e
    p
    • 3
    • 10
  • m

    Miguel Vera Belmonte

    01/22/2022, 11:05 AM
    Hi guys, has anyone had any success loading KSP-generated sources using the classloader after a
    kotlin-compile-testing
    compilation? It seems to be possible using KAPT (using
    result.classLoader.loadClass("com.pkg.GeneratedClass")
    ) but so far I haven’t got it to work with KSP. It seems like running the compilation only generates source files, but no
    .class
    files, so I’m guessing there’s some other gradle task involved that is not being run and it’s not possible yet…?
    e
    j
    m
    • 4
    • 6
  • j

    jeff

    01/23/2022, 3:41 PM
    I'm using Kotlin/JS with IR compiler:
    kotlin {
        js(IR) { ... }
    }
    and when I try to add ksp:
    plugins {
        ...
        kotlin("js") version "1.6.10"
        id("com.google.devtools.ksp") version "1.6.10-1.0.2"
    }
    it gives me this error:
    You already registered Kotlin/JS target with another compiler: legacy
    Googling indicates that ksp does support IR, I think? What am I doing wrong?
    j
    • 2
    • 5
  • i

    Irene Dea

    01/25/2022, 6:10 PM
    Hello, I'm considering using KSP to make copies of functions where if expressions/statements are replaced with function calls. For example, given
    fun f() { if(rand() > 1) println("a") else println("b") }
    , I'd like to make a copy with the if replaced:
    fun f_copy() { ifFunction(cond ={ rand() > 1}, b1 = { println("a") }, b2={ println("b") }) }
    . Would KSP be able to do this?
    🇳🇴 3
    t
    • 2
    • 1
  • p

    philglass

    01/27/2022, 9:19 AM
    What’s on the classpath used by the proxies returned from
    getAnnotationsByType
    ? Is it expected that
    KClass
    annotation parameters that reference user-defined classes won’t work? Both of these examples fail with a
    KSTypesNotPresentException
    ultimately caused by a
    ClassNotFoundException
    if I try to access the
    includes
    property on the proxy:
    @Module class First
    @Module(includes = [First::class]) Second
    
    @Module(includes = [FromUpstreamModule::class]) Third
    This works (it’s invalid for unrelated reasons, but the class lookup works):
    @Module(includes = [Unit::class]) Fourth
    This fails with the same exception but for a slightly different reason - it’s trying to look up
    kotlin.String
    at runtime (presumably it should be translated to
    java.lang.String
    at some point for JVM projects):
    @Module(includes = [String::class]) Fifth
    j
    g
    • 3
    • 11
  • f

    Forrest Pangborn

    01/28/2022, 7:25 PM
    Does a processor applied to a given module have visibility on elements that are invisible to the source for that module if those annotated elements exist within a dependency? What I'm looking to accomplish is to support generation of some classes internal to some collection of child modules, but then provide a simple way for resolving the generated classes in a consumer module. The mechanism for this would probably be by generating a map where keys are an interface the generated classes implement, where the keys are internal to the same places the generated classes (and thus only used in the modules where internal visibility applies), but I'm looking to have one central registry if possible, as that could itself also be generated. So: • Module A depends on Module B. • Module B contains some elements annotated with
    @XYZ
    . When a processor resolving elements annotated with
    @XYZ
    is applied to Module A, will the resulting processor execution resolve those elements from Module B that have been annotated with
    @XYZ
    ?
    j
    g
    • 3
    • 11
  • d

    Dutch

    01/30/2022, 1:33 PM
    In my Android project I'm resolving a specific, with KSP generated, class during runtime using the
    Class.forName(String)
    method. For some reason, when running instrumented tests I get a
    ClassNotFoundException
    . Even when adding the processor with
    kspTest
    and
    kspAndroidTest
    ...
    t
    g
    • 3
    • 8
  • a

    atlantis210

    01/31/2022, 7:45 PM
    Hello, can I use KSP on my project even if I use Dagger/Hilt ?
    j
    • 2
    • 2
  • j

    jeff

    02/01/2022, 8:07 PM
    KSP quickstart says to add
    "build/generated/ksp/*main*/kotlin"
    to your sourceSets. However I have a multiplatform project and the generated files are put in different folders depending on what target I'm building, e.g.
    "build/generated/ksp/*jvmMain*/kotlin"
    or
    "build/generated/ksp/*jsMain*/kotlin"
    . This is despite the fact that the actual code being processed is in
    commonMain
    . Therefore, I don't know how I can make my code in
    commonMain
    depend on generated code. Has anyone run into this?
    e
    • 2
    • 3
  • j

    janvladimirmostert

    02/02/2022, 8:46 PM
    Can KSP parse the variables inside a String template or is that not possible? Something like this maybe: @BlahTemplate() val template = """ Some static text ${ someVariable } ${ someVariable.toUppercase() } Some more static text """
    j
    • 2
    • 1
  • p

    Paul Woitaschek

    02/08/2022, 10:37 PM
    Then go with a gradle task
    g
    • 2
    • 1
  • g

    Gil Goldzweig

    02/08/2022, 10:37 PM
    I'm thinking of using both a plugin and KSP for different parts
    g
    • 2
    • 1
  • y

    yigit

    02/08/2022, 11:12 PM
    Processing layouts needs to be a Gradle task. But i don't think any of them are public API s such that you can define inputs outputs properly. Data binding does what you want, process files and provide inputs for the processor, yet all of setup is integrated in AGP. It is very very difficult to do it outside AGP due to different compilation modes (dynamic modules, namespaced resources, build variants etc). AGP also hooks those tasks' output as input to kapt. Don't get me wrong, what you want to do is totally reasonable but AGP just doesn't have the right public APIs to do that. If it is for your own project, you can make it work by hacking internals but for a public library, it is a losing battle😞
    g
    • 2
    • 7
  • l

    Lulu

    02/10/2022, 12:16 PM
    So I'm just trying to understand here. Can KSP show the user an error while they're writing the code if the semantics don't check out? (say for example, they used a type in the wrong place) and if so, how to enable such mechanism? My use case is basically making sure functions written by the user have parameters and return types that make sense to my library.
    g
    f
    +3
    • 6
    • 13
  • j

    jameskleeh

    02/16/2022, 3:04 PM
    Does anyone know why
    KSType
    does not extend
    KSAnnotated
    ?
    j
    z
    • 3
    • 6
Powered by Linen
Title
j

jameskleeh

02/16/2022, 3:04 PM
Does anyone know why
KSType
does not extend
KSAnnotated
?
It makes it difficult to handle without a single interface to represent things that have annotations
They both have
val annotations: Sequence<KSAnnotation>
j

Jiaxiang

02/16/2022, 5:06 PM
KSAnnotated
is a subtype of
KSNode
while
KSType
is not.
j

jameskleeh

02/16/2022, 6:47 PM
I’m aware of that, however my suggestion is that it would be useful to have a contract for just “something that has annotations”
j

Jiaxiang

02/17/2022, 12:40 AM
I see your point, changing class structure might be breaking for binary compatibilities. Generally, annotations on `type`s are considered different from annotations on symbols, in most of the time it should be sufficient to read annotations from
KSTypeReference
directly, are you processing annotations on actual types rather than the type reference?
z

Zac Sweers

02/17/2022, 5:48 AM
yeah this was my thought as well - this seems like something for KSTypeReference
View count: 15