I’ve got an issue and I have no idea where it coul...
# announcements
r
I’ve got an issue and I have no idea where it could come from. I’ve got a top level public extension function defined in the common part of a multiplatform project like this:
Copy code
fun HttpRequestBuilder.useAuthentication() { ... }
HttpRequestBuilder
is from Ktor client. I’m trying to use it in another project which has the above one as a dependency:
Copy code
private suspend fun postUploadFile(successUrl: String): Unit =
        <http://http.post|http.post>(successUrl) {
            useAuthentication()
        }
http
is a Ktor
HttpClient
. IntelliJ IDEA sees the extension, imported it alone without me doing anything, everything works inside IntelliJ. Then I tried to build.
Copy code
> Task :compileDebugKotlinAndroid FAILED
e: <myFile>.kt: (9, 37): Unresolved reference: useAuthentication
The reference position is in the imports. What could cause that? I’m posting here because I have no idea where to start. It only seem to happen for this top level extension right now. Maybe it’s a Gradle metadata issue? But then why would IntelliJ see it?
google 1
stackoverflow 1
h
#C0A974TJ9 probably?
r
Did you read my post?
h
Yes?
r
This is obviously not a ktor issue
h
You're writing an extension fun for ktor clients, you try to use the same within a ktor request…
r
You’re not helping
🤷 1
It could be caused by Gradle metadata changes, or maybe because it’s multiplatform
s
sounds like an issue with resolving your common module. I have this happen a lot if I am not using gradle's composite builds, but instead pushing to mavenLocal.
r
In this case the dependency is in an artifactory server. I'll try to clean everything and rebuild to see if that works
So I just tried to add
val test = 42
in the same file and same issue. IntelliJ sees it but not Gradle. So it’s not related to it being an extension nor to ktor. Can still be related to it being top level and/or multiplatform context maybe
Did the same with an
object Test { val test = 42 }
and that worked! So it’s due to it being top level.
Anyone knows what would be the cause of a top level `val`/`fun` defined in a lib not being visible to Gradle (but visible to IntelliJ) in lib users, while an
object
is visible?
d
is the IDE and compiler both using the same version of kotlin? Have you tried setting ktor common dependencies to API instead of implementation (if they're implementation right now)
r
I already found that it’s not related to Ktor, but I’ll change
implementation
to
api
for my parent lib in the child lib build file and see if it does anything
It doesn’t. I don’t use
api
because I don’t know what it does and never needed it...
j
Do you import
useAuthentication
?
Extensions are resolved statically…
r
Yes, the IDE imported it. The IDE sees it. There’s no error in IntelliJ, but I can’t build
🤔 1
I think I found what the problem was, checking
Yes. I had this in the parent lib:
Copy code
packagingOptions {
        exclude("META-INF/*.kotlin_module")
    }
This should not be set on libraries, only on apps. I had it set on a library.
👍 1