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

    El Zhang

    04/24/2022, 8:30 AM
    What would be the best practice for consuming generated classes by KSP? For example to create the instance of them, in JVM the app can leverage reflection, but what about Native/JS? Precondition: if we do not want users to execute ksp task once when interacts with generated classes.
    e
    s
    • 3
    • 3
  • c

    Chris C

    04/27/2022, 3:37 PM
    Hi 👋 I’m looking for a way to generate a class from a json file before/as part of my build. Would KSP be a viable way to do that?
    e
    d
    +2
    • 5
    • 19
  • d

    Dutch

    04/27/2022, 5:06 PM
    I have the following multi module project (see image) which works just fine. Sources are beeing generated/added and the app works just fine. Now I wanted to use the processor in a new app, and added A, B and C to the project, using
    implementation(files("libs/B.aar"))
    implementation(files("libs/A.jar"))
    ksp(files("libs/C.jar"))
    I'm getting the following error during kspDebugKotlin:
    java.lang.NoClassDefFoundError: _*Class from module A*_
    What am I doing wrong? EDIT: When adding A and B to KSP like so:
    ksp(files("libs/C.jar", "libs/A.jar", "libs/B.aar")
    It does find the class from module A. Now it is still missing a dependency which is used in A and my current project. EDIT 2: After adding every dependency with ksp() it is working now.
    j
    • 2
    • 1
  • d

    Dilraj Singh

    04/28/2022, 5:45 AM
    Hi everyone, I have an android project set up with ksp. When I am building the debug and release version in succession, I am getting a compile-time error saying that duplicate declarations are present. The issue is that ksp is building the same code under the debug folder and in the release folder. How can I solve this? I am attaching a screenshot for reference.
    t
    o
    j
    • 4
    • 18
  • e

    eygraber

    04/28/2022, 10:22 PM
    I updated from ksp 1.6.10-1.0.4 to 1.6.21-1.0.5 and
    kspMetadata
    configuration isn't found anymore. Is
    kspCommonMainMetadata
    the correct replacement?
    j
    • 2
    • 1
  • m

    Matthias Geisler

    04/29/2022, 6:51 AM
    Hello - Small question - when I use
    getSymbolsWithAnnotation
    with multiple deferring Annotation for a Class target. Is it suppose to pick up only the first?
    g
    e
    j
    • 4
    • 41
  • m

    martmists

    05/01/2022, 12:54 PM
    Given a KSFunctionDeclaration and a KType for a function, e.g.
    (String) -> Unit
    , is there an easy way to check if the KSFunctionDeclaration matches that signature?
    j
    • 2
    • 1
  • m

    Matthias Geisler

    05/01/2022, 6:17 PM
    Just an Observation I'd like to share - if I generate for example for commonTest something, neither
    getNewFiles
    nor
    getAllFiles
    picks them up - I believe this has to do with the fact that meta/shared sources (except commonMain) cannot be declared for KSP right?
    e
    j
    • 3
    • 9
  • h

    Harald Pehl

    05/04/2022, 7:29 AM
    Hi there, for a Kotlin/JS app, I’d like to show sample code on a web page. This sample code is the body of a lambda (but could also be refactored to a normal function / method. Currently I copy/paste the sample code into a multi line string constant and use that constant to show the sample code on the web page. Is it possible to mark the function containing the sample code with an annotation and use a KSP processor to extract the function body and generate a string constant with that exact source code? Ot is this only possible using a compiler plugin?
    g
    j
    • 3
    • 3
  • e

    eygraber

    05/06/2022, 6:17 PM
    Is there any plan to address https://github.com/google/ksp/issues/965 anytime soon?
    j
    • 2
    • 4
  • m

    Matthias Geisler

    05/10/2022, 6:12 PM
    Hey another week - another question. So please have a look at the thread.
    j
    • 2
    • 10
  • e

    El Zhang

    05/12/2022, 1:58 PM
    I created a tool to aggregate Kotlin Symbols for multi-modules development in compile-time, based on KSP. For instance, to gather all implementations of an interface across multi-modules, and later register/call them together in somewhere. https://github.com/2BAB/Koncat
    👍 1
    j
    • 2
    • 5
  • b

    Big Chungus

    05/12/2022, 9:47 PM
    Does anyone have any idea why default value for annotation argument is not being retrieved?
    // annotation
    @Target(AnnotationTarget.FUNCTION)
    @Retention(AnnotationRetention.SOURCE)
    public annotation class Showcase(
      val katalog: String = "katalog"
    )
    // application in sources
    @Showcase
    fun testTarget() {}
    // usage in processor
      private fun KSAnnotation.showcaseData(): ShowcaseVisitor.Data {
        arguments.first { it.name?.getShortName() == "katalog" }.value!! as String // throws NPE
      }
    I'm on ksp:1.6.21-1.0.5. I've also verified that the KSAnnotation at least contains the argument by that name
    j
    • 2
    • 6
  • m

    martmists

    05/14/2022, 11:00 PM
    > Task :kpy-sample:kspKotlinPy FAILED
    e: Compilation failed: Metaspace
    
     * Source files: MyClass.kt, Extra.kt, More.kt, kpy-module.kt, kpy-module.kt, entrypoint.kt
     * Compiler version info: Konan: 1.6.21 / Kotlin: 1.6.21
     * Output kind: LIBRARY
    
    e: java.lang.OutOfMemoryError: Metaspace
    It seems KSP is taking up a fair bit of memory, causing my github actions runner to crash. What should I do to reduce this? Here's the full error log:
    j
    • 2
    • 3
  • h

    Hamza GATTAL

    05/14/2022, 11:39 PM
    It's possible to use ksp with hilt instead of kapt?
    e
    • 2
    • 1
  • j

    Jiaxiang

    05/20/2022, 9:50 PM
    In case you are looking for it, kotlin 1.7.0-RC was released earlier today, and here is the KSP 1.0.5 release for Kotlin compiler 1.7.0-RC
    🎉 4
    ❤️ 2
    m
    • 2
    • 1
  • t

    trevjones

    05/20/2022, 10:44 PM
    Would it be possible to generate code from one source set into another via a KSP processor? Example being:
    @Parcelize data class Foo(val bar: String): Parcelable
    would generate something like
    @EnforceImpl abstract class FooRoundTripParceling {...}
    into the androidTest source set. Then I could have a different processor watching for annotations to pair the impl with a generated template. I assume generating some sort of resource file and doing a processor or gradle task that operates on the generated resources would be the only way to do something like this.
    j
    • 2
    • 2
  • j

    Jintin

    05/23/2022, 3:53 AM
    https://github.com/Jintin/KBuilder Create a tool to auto-generate builder pattern using ksp, hope this can showcase the power of ksp over annotation processing
    e
    p
    • 3
    • 7
  • e

    elect

    05/24/2022, 7:36 PM
    I'd like to completely parse a kt file, I can see all the top-level declarations in this way:
    resolver.getAllFiles().first { it.fileName == "terraform.kt" }.declarations
    but for functions, I can't "enter" and see the body, that is all the declarations inside is it a visitor mandatory?
    j
    n
    • 3
    • 7
  • n

    Norbi

    05/30/2022, 11:44 AM
    Does anyone use this project for testing? https://github.com/tschuchortdev/kotlin-compile-testing I tried to use this library but my pet example class is not recognized by the processor. (When I use "real" ksp processing it works as expected.) Example test file: https://github.com/kotlinw/kotlinw/blob/main/kotlinw-immutator-processor/src/test/kotlin/kotlinw/immutator/processor/TestKsp.kt Thanks.
    m
    • 2
    • 12
  • n

    Norbi

    06/02/2022, 10:08 PM
    What should I do to see KSP
    <http://logger.info|logger.info>()
    messages while compiling in Idea? Messages by
    warn()
    and
    error()
    is displayed on the console but
    info()
    is not. Thanks.
    j
    • 2
    • 1
  • q

    quicksteve

    06/03/2022, 6:21 PM
    Is there a way to change the KSP task input dependencies? Specifically we have modules A, B and C with C depending on A & B, but declaring only methods using A. KSP still waits for both A & B to compile though. As a workaround we currently have a submodule of C, which declares just A as a dependency containing a Sync task which copies all the parent kotlin sources to a temporary directory, then have the KSP task run with that.
    o
    • 2
    • 8
  • o

    Oliver.O

    06/03/2022, 7:34 PM
    I am working on fixing multiplatform issues with the KSP Gradle plugin. Details in 🧵.
    🎉 3
    f
    n
    +4
    • 7
    • 25
  • j

    Jintin

    06/05/2022, 5:12 PM
    Create another side project to build simple factory pattern easily leverage on ksp https://github.com/Jintin/Kactory/
    z
    • 2
    • 3
  • n

    Norbi

    06/07/2022, 8:40 AM
    I have a multiplatform multimodule project with KSP, where I'd like to generate classes in common code. In the docs there is a part:
    dependencies {
        add("kspMetadata", project(":test-processor"))
    ...
    In my project there seems to be no kspMetadata configuration:
    Configuration with name 'kspMetadata' not found.
    What is the correct configuration? Thanks. Environment: Idea 2022.1.2 CE, Kotlin 1.6.21, KSP 1.6.21-1.0.5
    j
    • 2
    • 2
  • m

    Michal Klimczak

    06/07/2022, 9:00 AM
    I'm trying to convert a library from kapt to ksp. In kapt I had a very useful kotlinpoet
    TypeElement.toTypeSpec(ClassInspector)
    extension. Then generating the code from the original TypeSpec was a breeze - e.g. just mapping original functions to their modified generated equivalents. I can't find an equivalent in KSP world, I would assume because there is no equivalent ClassInspector. I guess I could modify my generator classes to not rely on TypeSpec but rather something more abstract, but it would be super convenient if there was something similar. What am I missing?
    z
    • 2
    • 4
  • p

    Paul Woitaschek

    06/07/2022, 1:36 PM
    Is there a way to let ksp generate tests? I want to generate a test based on my main source set.
    👀 1
    j
    • 2
    • 8
  • a

    arnaud.giuliani

    06/07/2022, 4:25 PM
    Hello there 👋 is there a way to scan sources accross multiple gradle modules while using
    resolver.getSymbolsWithAnnotation(...)
    ?
    z
    j
    a
    • 4
    • 8
  • v

    Vaios Tsitsonis

    06/08/2022, 6:31 AM
    Hello! I have a class that I want to process and create a metadata class based on the field types. This class has an enum field. The enum declaration is located in a different gradle module. The problem is that the
    KSDeclaration
    of this enum does not contain the
    ENUM
    modifier (It has only the following modifiers:
    PUBLIC
    ,
    FINAL
    ). If I move the enum class into the same gradle module then the
    KSDeclarartion
    will have the correct modifiers. Is there some sort of limitation with multi-module projects or is it a bug?
    a
    j
    • 3
    • 4
  • m

    Michal Klimczak

    06/09/2022, 5:34 AM
    I can't make the tschuchortdev/kotlin-compile-testing library work with ksp. The files are generated and I can find them using this technique, but they don't seem to be compiled. So I tried to use a double compilation technique, but the second compilation fails with Unresolved references to both my own types and regular kotlin types, like
    kotlinx.coroutines.flow.Flow
    (everything works fine in kapt of course). Is it working for anyone?
    • 1
    • 1
Powered by Linen
Title
m

Michal Klimczak

06/09/2022, 5:34 AM
I can't make the tschuchortdev/kotlin-compile-testing library work with ksp. The files are generated and I can find them using this technique, but they don't seem to be compiled. So I tried to use a double compilation technique, but the second compilation fails with Unresolved references to both my own types and regular kotlin types, like
kotlinx.coroutines.flow.Flow
(everything works fine in kapt of course). Is it working for anyone?
ok, seems like
inheritClassPath = true
in the second
KotlinCompilation
helps
View count: 12