5

I use Spring Boot with Gradle, I execute this in Intelij:

10:43:37: Executing external task 'bootRun  -Drun.arguments="--
server.port=6666"'...

but still in logs I see:

Tomcat initialized with port(s): 8080 (http)

I have seen this, but it does not work for me: https://stackoverflow.com/a/37053004/3871754

Ivar
  • 6,138
  • 12
  • 49
  • 61
Kamil Nękanowicz
  • 6,254
  • 7
  • 34
  • 51

3 Answers3

7

Using Command Line Arguments with the Spring Gradle BootRun task isn't readily apparent. Here is a very interesting discussion on the topic in this Spring Boot Issue Thread.

How you can do it today is by passing all system properties to the bootRun task as mentioned in the thread, like this.

bootRun {
    systemProperties = System.properties
}

Then you can use simply:

bootRun -Dserver.port=6666

s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 6666 (http)

Kamil Nękanowicz
  • 6,254
  • 7
  • 34
  • 51
  • 1
    Could not find method bootRun() for arguments [build_2lc1lp789tqz1ov0hbgjhwn3q$_run_closure1@4f7ef951] on project –  Jan 16 '19 at 14:31
7

The following syntax worked for me without any change in the code:

bootRun --args='--server.port=6666'

Note: the single quotes are important

ddsultan
  • 2,027
  • 1
  • 19
  • 19
0

Spring Boot Gradle plugin still doesn't provide this functionality out of the box. But even if you don't want to add extra configuration to your Gradle scripts, it's possible to work around this using environment variables following the naming convention in these rules (works also for custom properties).

For example, you can change the port with:

SERVER_PORT=6666 ./gradlew bootRun
Helder Pereira
  • 5,522
  • 2
  • 35
  • 52