DEV Community

Discussion on: Publishing server-side Kotlin applications: Ktor on Heroku

Collapse
 
andresantospt profile image
André L. Santos

Thanks for the nice tutorial!
I'm having a lot of trouble with application.conf, where to place it, so that Heroku sees it. I can run the App in IntelliJ, but when using Heroku I get:
Exception in thread "main" java.lang.IllegalArgumentException: Neither port nor sslPort specified. Use command line options -port/-sslPort or configure connectors in application.conf

The image shows my project structure.

Any hints to overcome this?

Collapse
 
sebastianaigner profile image
Sebastian Aigner • Edited

Unfortunately I can't see an image, but if you're using the structure generated by the wizard, your application.conf should have been automatically placed in the right directory – resources/main/application.conf. Generally, application.conf needs to be inside your resources directory.

You could also trying running the application locally through your gradle wrapper (i.e. ./gradlew run, and see if that works. If not, it might be indicative of some other issue.

Collapse
 
andresantospt profile image
André L. Santos

thanks for quick answer!
(at the end the image did not attach... i'm new here)
perhaps like this is easier:
github.com/andre-santos-pt/qlciscte

gradlew run works well locally.

gradle stage, compiles ok, but when running the build I get that port error. (and the same when uploading to heroku)

Thread Thread
 
andresantospt profile image
André L. Santos

I forgot to mention that when generating a project like in your tutorial, it goes fine. my difference is that i'm doing the multi-platform Kotlin/KotlinJs

Thread Thread
 
sebastianaigner profile image
Sebastian Aigner • Edited

Thanks for sharing the project. I investigated this by running installDist locally, which creates a "start script" in /build/install/qlciscte/bin – and that indeed throws a IllegalArgumentException: Neither port nor sslPort specified.

And in fact, you're actually hitting a bug here! More specifically, KT-37964 Gradle application/distribution plugin does not copy and name jar files correctly when using installDist task for multiplatform project.

The TLDR: installDist generates a script with an entry point using your projects .jar, which the isn't properly being copied. The workaround:

distributions {
    main {
        contents {
            from("$buildDir/libs") {
                rename("${rootProject.name}-jvm", rootProject.name)
                into("lib")
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Hope this will be fixed in due time. Tripped me up as well, as you can see :)

You can also find a working Gradle configuration in the companion project for the "Building a Full Stack Web App with Kotlin Multiplatform" hands-on tutorial.

Thread Thread
 
andresantospt profile image
André L. Santos

now it works when I run the binary produced by gradle stage. however, when uploading to Heroku, the app still crashes. Here's the log entry:
2021-01-28T11:18:09.671617+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=qlciscte.herokuapp.com request_id=fbea81df-588f-443f-a520-7072d3110169 fwd="94.63.156.9" dyno= connect= service= status=503 bytes= protocol=https

It's not very informative. Do you know any trick to get a more detailed trace of what went wrong on Heroku?

Thread Thread
 
sebastianaigner profile image
Sebastian Aigner

Discovered the issue by running heroku logs --tail before actually triggering a build. That gave me:

2021-01-28T12:13:20.330000+00:00 app[web.1]: bash: build/install/untitled/bin/untitled: No such file or directory
Enter fullscreen mode Exit fullscreen mode

You might want to adjust the contents of your Procfile, since your project is no longer called untitled 😉

Thread Thread
 
andresantospt profile image
André L. Santos

meanwhile I also noticed that :) now I have another problem, but that has to with class version compilation of some libs i'm using.
thanks for the tip!