Grails 3 – Change Default Port

Grails application by default runs on 8080 port. But if required we can change the default port.

Prior to grails 3.x, we can change the port by running the application using following command:

grails -Dserver.port=8181 run-app

This command sets the given port temporarily. You have to use this command each time when you run the application.
If you want to change port permanently, i.e., the application by default runs on port other than 8080, then you can easily do this by adding following line in your BuildConfig.groovy file:

grails.server.port.http=8181

Recently grails 3.0.0 was released and they have changed the way of changing the default port:

  • For Temporarily-
    Run the application using following command:

    SERVER_PORT=8181 grails run-app
    
  • For Permanently-
    Add following lines in your application.yml file:

    server:
      port: 8181
    

Hope this helps. 🙂