Search code examples
kotlinarrow-kt

ArrowKT - @optics annotation not generating code


How do you setup the Arrow dependencies for @optics annotation to actually work? No companion objects are generated for the data classes annotated with @optics.

If I'm not mistaken, this is an annotation processor, so it should be imported using kapt, however the documentation uses it as compile.


Solution

  • For arrow 0.10.0

    apply plugin: 'kotlin-kapt'
    
    def arrow_version = "0.10.1-SNAPSHOT"
    dependencies {
        implementation "io.arrow-kt:arrow-optics:$arrow_version"
        implementation "io.arrow-kt:arrow-syntax:$arrow_version"
        kapt    "io.arrow-kt:arrow-meta:$arrow_version" // <-- this is the kapt plugin
    }
    

    then:

    @optics data class Street(val number: Int, val name: String) {
        companion object {} // <-- this is required
    }