yshrsmz / BuildKonfig

BuildConfig for Kotlin Multiplatform Project
Apache License 2.0
782 stars 32 forks source link

Support for nullable #20

Closed MikolajKakol closed 10 months ago

MikolajKakol commented 4 years ago

Hi, it would be great to add nullable support. Any thoughts about this? If help is needed I could try.

yshrsmz commented 4 years ago

Could you elaborate on this? What is the usecase of the null value as a constant?

MikolajKakol commented 4 years ago

I'm using Gradle properties to read some constants. I'd like to model absence of them.

What I do is defining in local.properties proxy address for app and if it's not defined like on CI it's not installed on http client.

yshrsmz commented 4 years ago

Thanks for the detail!

Do you really need to distinguish null and empty string? If not, I'd recommend you to use an empty string as an empty value, rather than using null.

kuuuurt commented 4 years ago

What about exposing a getHasKey method?

MikolajKakol commented 4 years ago

With String it's kind of okay... however I also have some int's there and modeling it as -1/0 is just, you know :)

I feel that it would be a good addition to support nullable types since it's very deep in Kotlin roots.

yshrsmz commented 4 years ago

That sounds reasonable. How would you like to configure nullable value? Any idea?

MikolajKakol commented 4 years ago

I'm using kts. The current method is buildConfigField I was thinking about adding simple buildConfigNullableField.

However, it's a bit more wast problem. Right now we are constrained by Type enum in FieldSpec. I think it maybe could be a sealed class and we should allow a user to enter any primitive supported by the language.

I could help with two PR, one for simple nullable and one that would try to tackle that second matter. It could also provide some type safety before compilation.

    fun <T: Any?> buildConfigField(
        name: String,
        value: T
    ) 

would be a perfect method signature if possible.

yshrsmz commented 4 years ago

buildConfigNullableField

looks nice 👍

Regarding the second suggestion, I'm not sure if it works well but let's see how it goes ;)

yshrsmz commented 4 years ago

I've just released 0.5.0 with changes from #21