Cannot build with arrow. Here's my build.gradle: `...
# arrow
n
Cannot build with arrow. Here's my build.gradle:
Copy code
plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.4.0'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    jcenter()
    maven { url "<https://dl.bintray.com/arrow-kt/arrow-kt/>" }
    maven { url "<https://oss.jfrog.org/artifactory/oss-snapshot-local/>" } // for SNAPSHOT builds
}

apply plugin: 'kotlin-kapt'

def arrow_version = "0.11.0"

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
    implementation "io.arrow-kt:arrow-optics:$arrow_version"
    implementation "io.arrow-kt:arrow-syntax:$arrow_version"
    kapt    "io.arrow-kt:arrow-meta:$arrow_version"
}
r
Hi @Nir Latest SNAPSHOT is
1.0.0-SNAPSHOT
(one number is missing in your code snippet). Please, let us know if that's the issue, thanks!
Sorry, I made a mistake with your version. I'm going to check it
n
cool, thanks!
Should I have a version listed for kotlin-kapt somewhere?
I've seen so many similar-but-different formulations of gradle build files at this point, it's so confusing
does gradle fetch packages lazily? If I don't have any code that uses arrow, then it works
r
@Nir, the error comes from a missing
package
in one of your code files. I'll improve that error to point to the file.
n
gotcha. can you explain what the fix should be? Here's my current code file:
Copy code
import arrow.optics.*

//@optics data class Foo(val bar: Bar) { companion object }
//@optics data class Bar(val bar: Baz) { companion object }
@optics data class Baz(val bar: Int) { companion object }

fun main() {
    println("hello world!")
}
r
Add a
package
as the first line before the imports
If you write something like
package com.nir
the IDE will suggest you to relocate the file under
src/main/kotlin/com/nir/
n
gotcha, okay, that is done, though interestingly intellij continues to highlight things in red
however, no when I try to get a lens, I still have issues
So now I have two files, foo.kt:
Copy code
package foo

import arrow.optics.*

@optics data class Foo(val bar: Bar) { companion object }
@optics data class Bar(val bar: Baz) { companion object }
@optics data class Baz(val int: Int) { companion object }
main.kt
Copy code
import foo.*

fun main() {
    val x = Foo(Bar(Baz(5)))
    val lens = Foo.bar
    println(x)
}
this builds but yields aruntime error
Copy code
"C:\Program Files\Java\jdk-12.0.1\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.1\lib\idea_rt.jar=59862:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\quick\IdeaProjects\untitled\build\classes\kotlin\main;C:\Users\quick\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.72\8032138f12c0180bc4e51fe139d4c52b46db6109\kotlin-stdlib-1.3.72.jar;C:\Users\quick\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.72\6ca8bee3d88957eaaaef077c41c908c9940492d8\kotlin-stdlib-common-1.3.72.jar;C:\Users\quick\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar MainKt
Exception in thread "main" java.lang.NoClassDefFoundError: arrow/optics/PLens
	at MainKt.main(main.kt:8)
	at MainKt.main(main.kt)
Caused by: java.lang.ClassNotFoundException: arrow.optics.PLens
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 2 more

Process finished with exit code 1
I'm confused as to why kotlin 1.3.72 is referenced here when in my gradle it's 1.4
r
About the runtime error, I cannot reproduce it with your code files. Please, could you run a clean before trying it again?
About the standard library, try to remove the dependency from the
build.gradle
because it's added automatically by the Kotlin plugin
n
Alright, I restarted the IDE
and it all works now... apologies for the bombardment, I'm quite new to kotlin and gradle (and arrow)
Copy code
fun main() {
    val x = Foo(Bar(Baz(5)))
    println(KotlinVersion.CURRENT)
    println(Foo.bar.baz.int.modify(x) {20} )
}
pretty nice!
r
Nothing to apologize! Happy to know that it's working for you, welcome!!
n
thanks!