Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module function cannot be found in 1.2.0 #1132

Closed
flaquir4 opened this issue May 15, 2019 · 19 comments
Closed

Module function cannot be found in 1.2.0 #1132

flaquir4 opened this issue May 15, 2019 · 19 comments
Assignees
Labels
Milestone

Comments

@flaquir4
Copy link

flaquir4 commented May 15, 2019

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?

@supertote
Copy link

I face the same problem. Migrating from 1.1.5 to 1.2.0
On windows with CIO server engine.

@flaquir4
Copy link
Author

flaquir4 commented May 15, 2019

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.

@lenalebt
Copy link

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.

@e5l e5l added the bug label May 16, 2019
@msenin
Copy link

msenin commented May 17, 2019

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 }
        }

@wskinner-eml
Copy link

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

@MinkiPan-zz
Copy link

any updates here? I am having the same error, tried the trick with removing the testing boolean, does not work

@davidepianca98
Copy link

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.

@rajohns08
Copy link

Same issue here...kind of a big deal that the default generated Ktor project from IntelliJ fails to run

@cy6erGn0m
Copy link
Contributor

Fixed in 1.2.1

@rodrigodevelms
Copy link

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

@tnc-tianwen
Copy link

I'm using 1.2.1 too. And get the same error.

@herveDarritchon
Copy link

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.

Works fine for me ! Thanks !!

@milosmns
Copy link

This is reproducible on 1.2.0 for me too, on a clean project, just created through IntellIJ IDEA. So creating and running a new empty project is broken, this should be a showstopper. I followed Ktor Getting Started docs.

@aloon
Copy link

aloon commented Jun 15, 2019

With 1.2.1 works fine for me -#1132 (comment)

@milosmns
Copy link

Verified fixed in 1.2.1

@alexsvdk
Copy link

Check the package of your kt file

@geofflangenderfer
Copy link

geofflangenderfer commented Jan 21, 2021

The name must match what you have in application.conf

    application {
        modules = [ geofflangenderfer.ApplicationKt.module ]
    }

Fail

fun Application.mainModule() {
...
}

Success

fun Application.module() {
...
}
``

@NullByte08
Copy link

Try marking resources directory(the directory which contains the application.conf) as resources root. i.e. right-click on resources directory->Mark directory as-> Resources Root.
And src as sources root.

@gandrewstone
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests