Gradle 4.9 introduced the --args parameter to bootRun, which I can use easily from the command-line, but how do I use this from a Run/Debug configuration in Intellij 2018?
With a Gradle build set to run the bootRun task on my project in Intellij, I've tried the following arguments in the Run/Debug Configurations screen without any success:
--args 'foo'
--args='foo'
--args=foo
Output from Intellij:
9:18:56 AM: Executing task 'bootRun --args='foo''...
Unknown command-line option '--args'.
9:18:57 AM: Task execution finished 'bootRun --args='foo''.
A similar question documents the older syntax for doing this.
Maybe you can add your args to Tasks as bootRun --args='foo' in IDEA's Run/Debug Configurations.
My task is run --args='-h' and it works for me
Unfortunately, #Linsama's workaround will not work with multiple arguments. For example, run --args='--arg1 --arg2' will not work.
For multiple arguments, you have to move the entire thing in the Arguments field and leave the Tasks field blank.
This will work:
Tasks:
Arguments: run --args='--arg1 --arg2'
As a workaround you can use gradle properties.
In intellij Arguments field add -Pargs=--myArg=value
Then in your build.gradle add
bootRun {
if (project.hasProperty('args')) {
args project.args.split(',')
}
}
They should be now accesible using ApplicationArguments inside your application.
Related
When I run ./gradlew bootRun, I'd like for the npmInstall task that it depends on to run with the "--force" or "--legacy-peer-deps" arguments.
I tried using ./gradlew bootRun npm_install_--force but this doesn't make the npm install task that runs before the bootRun task use the --force argument. How can I pass either one of these arguments to the npmInstall task?
I'm running on windows and I need either one of these arguments so that I can resolve angular dependency issues. The npm version is 8.19.2
You should be able to create an .npmrc file with the following contents to solve this:
legacy-peer-deps=true
Is there a way to pass command line arguments to a program executed via Gradle run task in IntelliJ IDEA?
In the terminal, I can simply do this:
./gradlew run --args="-hello", which will pass the command line argument '-hello' to the program as expected.
However, if I add --args="-hello" to the IDEA Run Configuration (as in the image below), all I get is an error, which reads "failed", with this output:
10:08:50: Executing task 'run --args="-hello"'...
10:08:50: Task execution finished 'run --args="-hello"'.
A similar question, but no good answer: How do I use Gradle bootRun with --args in Intellij
Apparently this is a known issue in IntelliJ IDEA: Cannot use Gradle 4.9 --args option in "Arguments" field of a Gradle run configuration
The solution that worked best for me was to insert the run command in the Arguments section:
If I place the line run --args="-username=john -password=wayne" in the Tasks field (as also suggested in the link), it will complain about unmatched quotes due to the space between the two arguments.
Arguments can be passed by adding --args="" to the run section.
This question already has answers here:
How to run bootRun with spring profile via gradle task
(15 answers)
Closed 3 years ago.
I am trying to learn using gradle with springboot from maven so I wanted to know how I can run my project in command line to pick up a different configuration file.
The scenario here is I have my properties eg.
application-qa.properties and application.properties
however If run gradle with something like ./gradlew -PspringProfile=qa bootRun
It loads only the default properties in application.properties and not the qa properties.
How do I accomplish that with gradle as with maven before?
This is what I have tried.
I created gradle run config in IntelliJ but this has not also worked,
Is there a commad-line option?
First of all, as another user said in the comments to your question, you are not using the correct name of the parameter.
But furthermore, you can't set the active profile with a project property through -P (at least not out of the box). You have a few other options.
A
Use --spring.profiles.active=qa as an argument like this:
gradlew bootRun --args='--spring.profiles.active=qa'
I don't think you can put that type of argument into the "arguments" list in the IntelliJ run configuration though, but you can put it directly into the "tasks" value instead if you like. But that's a bit weird.
B
Default to a particular environment in the Gradle build file when run though Gradle:
bootRun {
environment('spring.profiles.active', 'qa')
}
This makes sense if you are always running against the same environment when using the bootRun task from Gradle.
C
Set an environment variable spring.profiles.active=qa, either on your local computer or in the IntelliJ run configuration.
I am having an application, which is running on some port(ex-8080) now when I start this application using gradlew I want to pass dynamic port to start the application?
./gradlew :testApplication:bootRun
is there anyway to pass the dynamic port here??
Add the following to build.gradle so that we can pass parameters to gradlew along to the underlying java command:
bootRun {
if (project.hasProperty('args')) {
args project.args.split(',')
}
}
Pass the arguments you would normally send to a java command (in this case, overriding the server.port) as -Pargs to gradlew:
/gradlew :testApplication:bootRun -Pargs="--server.port=8081"
What is here:
When you run java with arguments --server.port=8081, Spring Boot will override default property (e.g. Spring Boot will ignore your port in properties file, it will use value from command line
-Pargs is the way to ask bootRun to command line arguments. See details here.
See also the same question for maven.
I couldn't pass the port directly.
But if you want a workaround, do the following:
Build the application with gradle build.
Navigate in your project and open the directory build/libs
Now you have to see the jar of your project and then run this command java -jar yourJarProject.jar --server.port=8081.
I'm a relatively new user with Gradle, I'm working for the first time on a project (and first time with JHipster as well).
To run my application through the terminal, I execute the following command:
gradlew.bat
But at each new modification I have to kill the application ctrl + c and run it again.
I already tried using the command gradlew.bat -t build -x test (I don't want to run test each time) and gradlew.bat --continue, but both did not work.
As the bootRun task, which is the default task gradle doesn't know when to start watching, so it is not possible with gradle only. Using your ide (e.g. intellij) and the springboot devtools it is possible.
Start the application from our ide
Make changes in the code
In intellij press ctrl + F9 to compile the code and the application should restart
When you want to do it with gradle only you need two terminals and start e.g. javaCompile in continuous mode and bootRun in another terminal. The boot devtools will take care of restarting the application when it detects the newly compiled files.
gradlew compileJava -t in on terminal
gradlew bootRun in another terminal