How to add -P parameter to Gradle launch config?

Answered

From the command line I run my app with this -P parameter

./gradlew wp-web:backend:bootRun -PskipFrontendBuild=true

I can't figure out how to get it to work using a Gradle launch config in IntelliJ 2023.1. I've tried VM options and Program arguments and neither work. How can I get the run launch config to use a -P parameter when using Gradle to run? This -P parameter is used in build.gradle and not in the app. 

 

0
4 comments

>I've tried VM options and Program arguments and neither work.

Since you want to pass a gradle parameter, you should use Gradle run configuration ype insted of the Spring Boot run configuration type to pass this parameter:

  1. Open the Gradle view by clicking on the "Gradle" tab on the right side of the screen.
  2. Navigate to your project and expand it to show the available tasks.
  3. Right-click on the task you want to run and select "Create [task name]..." from the context menu.
  4. In the "Create Run Configuration" dialog that appears, append the -P parameter in the "Run" field.

Alternatively, you can modify the build.gradle file directly in IntelliJ IDEA by adding the parameter to the "bootRun" task. For example:

bootRun {
    systemProperties['skipFrontendBuild'] = project.hasProperty('skipFrontendBuild') ? project.skipFrontendBuild : false
}

This will set the "skipFrontendBuild" property to true if the -PskipFrontendBuild=true parameter is passed in from the command line.

0

Thanks for the help and it works, but wondering if there's a way to get it to run under Services tab? It currently runs under the Run tab. I would love to be able to start it under the Spring Boot/Services folder as I need all of these running. 

0

Also, I didn't get the Create task right-click option that you mentioned in step 3. I did Modify Run Configuration... so maybe the same thing?

0

>wondering if there's a way to get it to run under Services tab?

Yes, you can add Gradle run configuration type to be displayed under the Services tab.

>Also, I didn't get the Create task right-click option that you mentioned in step 3. I did Modify Run Configuration... so maybe the same thing?

Yes, you are correct, sorry for the wrong option name.

0

Please sign in to leave a comment.