Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Grails Port when Running with Gradle

Tags:

gradle

grails

I had a tough time to set the port of a Grails project to something other than 8080. The project was set up with Gradle. I tried all the ways I can think of and found on Google but it does not work. The methods I tried include

./gradlew run -PgrailsArgs="-Dgrails.server.port.http=9090"
./gradlew run-app -PgrailsArgs="-Dgrails.server.port.http=9090"
./gradlew grails-run-app -PgrailsArgs="-Dgrails.server.port.http=9090"
./gradlew run -Dgrails.server.port.http=9090
./gradlew -Dgrails.server.port.http=9090 run
./gradlew grails-run-app -PgrailsArgs="--port=9090"

as well as out the grails.server.port.http property in build.properties, Config.groovy and build.grade. None works. It is hard.

Probably grail run-app may work with one of the above option (also using BuildConfig.groovy). But "grails run-app" always resulted a resolving error for org.aspectj:aspectjweaver:1.8.5. I don't see how to get around this way either.

Any help will be greatly appreciated.

like image 465
hanaZ Avatar asked Jan 14 '16 10:01

hanaZ


2 Answers

You can also set port like this

-Dgrails.server.port=9090

when you start server using Gradle. It works for me

like image 171
Sergey Linnik Avatar answered Sep 28 '22 10:09

Sergey Linnik


You are using incorrect property name I guess i.e. grails.server.port.http. It should be server.port.Hence try ... -Dserver.port=8256 etc.

Also, you could specify it in your build.gradle task which you are using to run your application as below. For example you are doing it for springboot application using gradle bootRun.(I actually don't have much working experience in grails 3.0 but have in springboot)

bootRun {
   systemProperty 'server.port', '8086'
}

This will run your application on 8086 port.

In general, you could try

gradle your_task_to_run_app -Dserver.port=your_port

Also, if you have application.yml in grails 3 app(as grails 3 uses gradle and springboot.If not present you should be able to create one) then do it like below:

app:
 name:Springboot+Config+Yml+Demo
 version:1.0.0
settings:
 counter:1
---
spring:
 profiles:development
server:
 port: 9001
security:
 user.name: 'default'
 user.password: 'default'

Let me know it works or not as haven't tried but pretty sure that it will work.

Edit: More this should help! Hope it helps!

like image 36
Vinay Prajapati Avatar answered Sep 28 '22 12:09

Vinay Prajapati