28

In Grails3 grails -Dserver.port=9001 run-app doesn't appear to work:

I'm "getting address already bound 8080".

Any idea how to do this - ideally by passing a property to "gradle run"?

Shashank Agrawal
  • 21,660
  • 9
  • 71
  • 105
Neill Robbins
  • 409
  • 1
  • 4
  • 4

4 Answers4

39

You can use

server:
  port: 9001

in application.yml.

Or you can pass it via system environment. (e.g. SERVER_PORT=9001 grails run-app).

dmahapatro
  • 46,408
  • 7
  • 75
  • 111
23
grails run-app --port=8081

Or in interactive mode:

run-app --port=8081

Don't forget to use the same port when you want to stop the server:

stop-app --port=8081

I believe this feature was broken in 3.0.3 and earlier versions but it definitely works in 3.0.4.

and
  • 1,774
  • 1
  • 18
  • 26
4

Accepted answer is correct. For some additional info, Grails 3 uses spring-boot and the server properties are configured by the

org.springframework.boot.autoconfigure.web.ServerProperties

class. "port" is just a property on this class which is filled from the application.yml with the prefix "server". So in addition to the port, you can set properties of this class including tomcat configuration properties and etc. To change the contextPath for instance you add

server: 
   contextPath: /myapp

to you application.yml.

Cagatay Kalan
  • 3,970
  • 1
  • 26
  • 23
3
  server:
  port: 9809
  contextPath: '/admin/'

you can use this in your application.yml file

or change the port depends on the environment for example :

    environments:
        test:
            grails:
                serverURL: "http://localhost:9809"