https://kotlinlang.org logo
#akkurate
Title
# akkurate
j

Johann Pardanaud

10/16/2023, 6:46 PM
About 3rd party types, actually this is just not documented yet, but it's already possible through a KSP plugin option! You just have to provide a list of FQCN to the validatableClasses option.
d

dave08

10/17/2023, 10:18 AM
Lets say I write (in my test module):
Copy code
@Validate
data class Fixture(val foo: Foo, val baz: Baz)
will the ksp plugin generate accessors for Foo and Baz (from the main module), even though ksp is only enabled in the test module, since it has to generate for
Fixture
anyways?
j

Johann Pardanaud

10/17/2023, 11:26 AM
No, you will only have accessors generated for
Fixture
The reason I did not do this is to avoid generating to much accessors without the developer being aware of this, I don't want this to snowball. Maybe I will change this behavior in the future, nothing is settled.
d

dave08

10/17/2023, 11:32 AM
I'd understand that reasoning, but just as long as you don't generate double accessors (for classes already annotated + transitive), you could always provide an expiremental
@Validate(generateTransitive=true)
or something similar, that way it's only opt-in.
j

Johann Pardanaud

10/17/2023, 11:44 AM
I will think about it! But, couldn't the
validatableClasses
option do the trick in your case? It also avoids creating a dummy
Fixture
class.
d

dave08

10/17/2023, 11:45 AM
It could, but it's a bit cumbersome to have to provide a very big list of FQCNs...
j

Johann Pardanaud

10/17/2023, 11:46 AM
I can understand 🙂
d

dave08

10/17/2023, 11:48 AM
internal var validatablePackages: Set<String> = emptySet()
is not yet implemented I suppose?
j

Johann Pardanaud

10/17/2023, 11:48 AM
its implemented… privately 😅 the reason is simple: it uses an experimental feature of KSP
but I really don't recommend it!
d

dave08

10/17/2023, 1:10 PM
Btw, how do I set that property? Using the
ksp { arg("???", "????" }
block in build.gradle.kts? How would I separate the list of packages, one humongous string?
j

Johann Pardanaud

10/17/2023, 1:18 PM
yes, use the
ksp { arg(...) }
block, you can write something like that:
Copy code
ksp {
    arg("validatableClasses", "org.example.Foo|org.example.Bar")
}
Unfortunately, ksp plugins only accept strings as option values, so have to use a "humongous string" like you said 😅, each class separated by a
|
You can improve the readability by joining multiple strings into one:
Copy code
listOf("org.example.Foo", "org.example.Bar").joinToString("|")
👍🏼 1