https://kotlinlang.org logo
Docs
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
  • n

    no

    02/22/2022, 7:52 AM
    Hi there, I was curious, what is the expected order of execution when both KSP and KAPT exist in the same module?
    j
    • 2
    • 4
  • s

    spierce7

    02/23/2022, 9:06 PM
    if I use KSP to generate an extension function or a class in a module, do I have the ability to see that function and use it in code in the same module?
    j
    t
    • 3
    • 7
  • m

    Matthias Geisler

    02/24/2022, 1:54 AM
    @Ting-Yuan Huang first of thx for the fast release of 1.0.4! However in 1.0.4 I noticed that the folder structure for KMP changed. While on 1.0.2 you had for example
    ksp/jvmTest
    , it is in 1.0.4.
    ksp/jvm/jvmTest
    . Is that change intensional?
    t
    • 2
    • 5
  • p

    PixelHamster

    02/26/2022, 3:37 PM
    Hi, when processing annotations can I somehow know when it processed the last annotation so I can write the end of a file and close it ?
    j
    • 2
    • 2
  • m

    myotive

    03/01/2022, 11:49 PM
    Is there a good place to discuss Kotlin Compiler Plugin’s (I know this is for KSP discussions, but I couldn’t find an alternative channel)? I’m trying to write a plugin that will add Gson’s
    @SerializedName
    annotation and Moshi’s
    @Json
    annotation to all the properties of a data class. Everything seems to be working in my transformer (
    IrElementTransformerVoidWithContext
    ) , but the resulting class doesn’t seem to have the annotations when I try to run a unit test (which loads the class from a temp working directory). If anyone has any documentation or resources that could help, I would be most grateful. Thanks!
    z
    • 2
    • 4
  • j

    jameskleeh

    03/16/2022, 12:12 AM
    Is there a way to get javadoc with KSP?
    j
    • 2
    • 3
  • j

    jean

    03/16/2022, 8:34 PM
    I made a custom multiplatform plugin similar to this one https://github.com/google/ksp/tree/main/examples/multiplatform it works great but now I’m a bit lost on how I can publish it as a maven package so I can reuse it in other projects. Is that even doable?
    j
    m
    y
    • 4
    • 8
  • m

    Matthias Geisler

    03/17/2022, 7:48 PM
    Hey - is there any possibility to extract alias names for KSDeclaration?
    y
    j
    • 3
    • 5
  • j

    jameskleeh

    03/18/2022, 3:13 AM
    What is the recommended way to get the visibility of a KSPropertySetter?
    t
    j
    • 3
    • 5
  • m

    Matthias Geisler

    03/22/2022, 5:12 PM
    @Jiaxiang may I make a suggestion in terms of KMP? Do you want it as issue or you like to chat here about?
    j
    a
    t
    • 4
    • 10
  • a

    Andrea Di Menna

    03/23/2022, 12:23 PM
    hi guys 🙂 I am developing a simple KSP annotation processor and applying it on a sample android library project, which has
    debug
    and
    release
    build types. Different source folders are created for each build type, i.e.
    build/generated/ksp/debug/kotlin
    and
    build/generated/ksp/release/kotlin
    respectively. In order to be able to consume the generated code I have added the following code in my
    build.gradle.kts
    buildTypes {
            getByName("debug") {
                sourceSets {
                    getByName("main") {
                        kotlin.srcDir(file("build/generated/ksp/debug/kotlin"))
                    }
                }
            }
            getByName("release") {
                sourceSets {
                    getByName("main") {
                        kotlin.srcDir(file("build/generated/ksp/release/kotlin"))
                    }
                }
            }
        }
    Unfortunately, if I run
    kspDebugKotlin
    and
    kspReleaseKotlin
    w.o. cleaning the
    build
    folder my generated classes are marked with errors in Android Studio. The error reads
    Redeclaration
    as if both folders were added to the same source set. Do you know how to get rid of this error? Using: • ksp
    1.5.31-1.0.0
    • Kotlin
    1.5.31
    • Android Studio Bumblebee • AGP
    7.1.0
    e
    j
    • 3
    • 6
  • e

    efemoney

    03/23/2022, 6:45 PM
    👀 https://kotlinlang.slack.com/archives/C0KLZSCHF/p1648040697724719
    j
    • 2
    • 1
  • t

    TwoClocks

    03/26/2022, 3:35 AM
    I'm trying to convert some kapt annotations to KSP. and gradle is blowing up w/
    FileAlreadyExistsException
    . It seems really hard to get any debugging info out of grradle, but I think my annotation process is only called once, and the annotation only exists once. Any ideas? The file it's complaining about is a file I generate.
    y
    • 2
    • 6
  • t

    TwoClocks

    03/26/2022, 11:53 PM
    The next thing: Sometimes my processor isn't called when building (gradle), and no code is generated (the output directory is empty). The only way I can get gradle/ksp to call my processor again is to touch/change the processor code itself. I feel like I'm not understading dependencies correctly. I'd like the processor to run if the resulting files don't exist....
    y
    j
    • 3
    • 8
  • m

    mkrussel

    03/31/2022, 9:05 PM
    How do you get the documentation for a constructor. I found a class, and used the
    primaryConstructor
    to get the constructor. With the following code the constructors
    docString
    property is null.
    /**
     * A fake service that needs to be removed.
     */
    @MainThread
    @NotThreadSafe
    public class FooService @GenerateOptions
    /**
     * The constructor.
     *
     * @param other The other thing
     */
    public constructor(
        /**
         * The bar.
         */
        @get:MainThread public val bar: Int,
    
        /**
         * The id.
         */
        @get:MainThread public val id: String? = null,
        other: String? = null,
    )
    j
    • 2
    • 9
  • z

    Zac Sweers

    04/02/2022, 5:57 PM
    fyi, looks like 1.6.20 stable had one more breaking change https://github.com/google/ksp/issues/923
    😔 1
    👍🏻 1
    ➕ 1
    t
    • 2
    • 3
  • v

    Vladimir Tagakov

    04/06/2022, 3:42 AM
    Howdy! I’m reading
    KDoc
    for
    com.google.devtools.ksp.symbol.KSTypeReference#resolve
    and it says
    Calling [resolve] is expensive and should be avoided if possible.
    Does anyone know should I bother about memoizing the result if I plan to call
    resolve
    several times on the same type in different places? Or is it being cached somewhere inside?
    t
    • 2
    • 2
  • h

    haoxiqiang

    04/07/2022, 4:00 AM
    Hi!
    @Layout(R.layout.album_medium)
    class AlbumViewHolder(view: View) : FlowHolder<Album>(view) ...
    I have two problems 1.when I used KSAnnotated.annotations, I have got the int value of R.layout.album_medium, Is there any way to get the defined text? 2.I want to get Album class defined by Layout annotation. Could I get it from KSAnnotated? If not, what should I do?
    y
    j
    • 3
    • 5
  • d

    Dmitriy Tarasevich

    04/10/2022, 7:25 PM
    I'm running into an issue where
    getSymbolsWithAnnotation
    returns 0 symbols when my modules are only targeting the
    jvm
    . If i re-add my
    js
    or
    ios
    targets it picks up the annotations correctly.
    j
    • 2
    • 8
  • r

    Rafael Costa

    04/12/2022, 2:43 PM
    This is maybe a bit of a non related question, but at the same time it’s a unique question to code generation, since we generate classes on the consumer module. So I appreciate any help I get! 🙏 Is there an issue with generating code annotated with
    @Keep
    (from Android) and will it always work in a way that I can safely call it via reflection from my library? Or should I just use a rule on the consumer proguard? (I’m not sure if I can write rules for classes from other modules, although I’m guessing I cannot?)
    m
    • 2
    • 2
  • j

    Justin Tullgren

    04/12/2022, 6:01 PM
    Hello, I saw a Tweet from Jake Wharton saying that KSP is released within hours after a kotlin release. I was wondering if anyone had blog posts or thoughts that could share about how thats accomplished? We manage an Android SDK that could benefit from turn around like that for kotlin updates. Thanks!
    p
    t
    +3
    • 6
    • 22
  • e

    efemoney

    04/14/2022, 2:16 PM
    This might be a bug in ksp so I’m just posting here for awareness but did something change in ksp (from 1.0.2 to 1.0.5) regarding typealiases? https://github.com/square/moshi/issues/1530
    👀 2
    t
    y
    • 3
    • 4
  • g

    Grégory Lureau

    04/14/2022, 8:32 PM
    Hi! Is there some way to retrieve the name of the current module being processed? (I'm generating documentation on a multi-module project.)
    t
    a
    j
    • 4
    • 8
  • c

    charbgr

    04/20/2022, 10:39 AM
    Hello folks! Is there a way to produce classes from main sources to only test sources?
    j
    • 2
    • 13
  • m

    martmists

    04/20/2022, 5:48 PM
    How would I use KSP in a gradle plugin to generate additional code based on annotations? I was working with an IR plugin before, but generating code instead of IR seemed better suited for my use case.
    b
    t
    • 3
    • 13
  • m

    martmists

    04/21/2022, 8:54 AM
    How do I tell if a given KSFunctionDeclaration refers to an operator method?
    j
    • 2
    • 1
  • g

    Grégory Lureau

    04/21/2022, 7:51 PM
    Testing the 1.6.21-1.0.5 and it looks like a simple Kotlin interface now has
    kotlin.Any
    (which is a class) as
    superTypes
    , is there a reason for that?
    j
    • 2
    • 2
  • n

    Norbi

    04/22/2022, 4:22 PM
    What is the correct way to interrupt/stop ksp processing with a friendly compiling error message when an error is detected "deeply" during processing? If I throw an exception it causes an internal compiler error. Thanks.
    g
    • 2
    • 1
  • o

    Oliver.O

    04/22/2022, 6:01 PM
    Some questions regarding incremental compilation. Details in thread.
    t
    • 2
    • 3
  • c

    Cornelius Wichering

    04/22/2022, 7:47 PM
    Hi! I want to dynamically add (or replace) annotations to Methods. For example if I annotate a Method in my source like this:
    @OneAnnotation(value = "someDetail")
    fun methodA() { ... }
    I want ksp to add another annotation like this
    @AnotherAnnotation(value = "someDetail") // value taken from "original" annotation
    @OneAnnotation(value = "someDetail")
    fun methodA() { ... }
    Do you think ksp is a good fit for this task? Any hints on how to do it?
    y
    • 2
    • 2
Powered by Linen
Title
c

Cornelius Wichering

04/22/2022, 7:47 PM
Hi! I want to dynamically add (or replace) annotations to Methods. For example if I annotate a Method in my source like this:
@OneAnnotation(value = "someDetail")
fun methodA() { ... }
I want ksp to add another annotation like this
@AnotherAnnotation(value = "someDetail") // value taken from "original" annotation
@OneAnnotation(value = "someDetail")
fun methodA() { ... }
Do you think ksp is a good fit for this task? Any hints on how to do it?
y

yigit

04/22/2022, 7:48 PM
No, you need a compiler plugin for that. KSP does not allow modifying code
c

Cornelius Wichering

04/22/2022, 7:50 PM
Ah ok, thank you :D
View count: 9