ktor: Module function cannot be found in 1.2.0

Ktor Version

1.2.0

Ktor Engine Used(client or server and name)

Ktor server

JVM Version, Operating System and Relevant Context

java version “1.8.0_151” MacOS

Feedback

I’ve migrated mi running project from 1.1.5 to 1.2.0 and I’ve the following error.

Exception in thread "main" java.lang.ClassNotFoundException: Module function cannot be found for the fully qualified name 'cat.helm.catformacio.ApplicationKt.module'

Has the configuration changed?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 19 (1 by maintainers)

Commits related to this issue

Most upvoted comments

This worked for me ONLY if my file name was exactly Application.kt (I had chosen server.kt), and my function as: fun Application.module() {} (no parameter). This differs from the ktor docs https://ktor.io/docs/create-server.html#engine-main.

The design decision to wrap “main” and force the user to conform to your custom “main” format is never a good one because your lib is not the heart of my program. Let me be in control and pass you a callback function, if you absolutely MUST schedule the run of “main” yourself.

The decision to define what is “main” in a conf file is even crazier. What web app needs entry point A today, but tomorrow somehow there’s a compelling reason to stop the server (which should never happen) and restart at entry point B?

This whole .conf file is just one more thing that can go wrong, and is massive overkill to define the port and IP, as is clear by all the search hits (should be optional).

The “embeddedServer” interface is nice clean and kotlin-like. But based on the docs, etc, it seems like it may be meant for debug not deploy? Does it have perf or other limitations? If it does not, it would be nice to make that clear.

Same problem. It is not good that users cannot run projects generated by KTor website 😦

In ApplicationEngineEnvironmentReloading.kt at last line of isApplicableFunction for default boolean parameter we have it.kind == KParameter.Kind.VALUE, not KParameter.Kind.INSTANCE.

        private fun KFunction<*>.isApplicableFunction(): Boolean {
            if (isOperator || isInfix || isInline || isAbstract) return false
            if (isSuspend) return false // not supported yet

            extensionReceiverParameter?.let {
                if (!isApplication(it) && !isApplicationEnvironment(it)) return false
            }

            javaMethod?.let {
                if (it.isSynthetic) return false

                // static no-arg function is useless as a module function since no application instance available
                // so nothing could be configured
                if (Modifier.isStatic(it.modifiers) && parameters.isEmpty()) {
                    return false
                }
            }

            return parameters.all { isApplication(it) || isApplicationEnvironment(it) || it.kind == KParameter.Kind.INSTANCE }
        }

Fixed in 1.2.1

Can confirm. This way it works:

@Suppress("unused") // Referenced in application.conf
fun Application.module(testing: Boolean) {

}

@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module() {
    //...
}

However, with a default parameter and @JvmOverloads, it does not.

My problem was that i whas ussing:

fun Application.module(testing: Boolean = false) {} It seems that now the parameter is not allowed, so I’ve had to add a wrapper function without parameter.

So for me you can close the issue.

It’s Not fixed yet. I’m using 1.2.1 and getting the same error. Only works using davidepianca98 solution.

The solution for we was removing both the testing parameter and the JvmOverloads annotation so that now it’s just fun Application.module() { But waiting for a real fix because the testing boolean was useful.

I have the same problem. Also macOS, JDK8, ktor 1.2.

Check the package of your kt file