Spring Boot Gradle – How to Change the Port of an Application

gradleportspring-boot

The simple question is: How can you change the Spring Boot application port with gradle?


Here are already listed a lot of correct answers if you are not using gradle. So for none gradle issues, please refere to this post.

Best Answer

In case you don't want to add extra configuration to your Gradle scripts, you can achieve it by setting the SERVER_PORT environment variable:

SERVER_PORT=8888 ./gradlew bootRun

[UPDATE] Since Gradle 4.9, it's possible to pass arguments to bootRun without extra configuration:

./gradlew bootRun --args='--server.port=8888'
Related Question