Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Script parameters(such as -Penv) with Intellij

Background:

I've been using Eclipse for a while and am trying out Intellij now.

I checked out my project from Git (via Intellij) and recognized it as a gradle project. Its created the WAR(& the exploded WAR) all of which are fine.

Question:

When I was using Eclipse, I used the command:

gradlew -Penv=Development :my_webapp:assemble

This used to do a few things including creating a environment.properties file that my dev specific env could use (for selecting database instances etc) based off of -Penv=Development...I'd like the Intellij gradle build to do the same... What's a way to configure Intellij's gradle process to do these custom things or provide same features as provided by this specific command line tool (Note - the code for this is already written in build.gradle file)...

I looked at some of Intellij's docs, but could not find an answer to this.

EDIT:

I've found the solution, for anyone interested - read on...

Seeking guidance from @Stanislav, I was able to add the property as follows:

  1. In your server's run configuration (Run/Debug Configuration -->Your server's config(Jetty etc), there is a section called Before launch, which should have Make/Build Gradle already included
  2. Hit the + sign -->Run Gradle Task --> Select your gradle project (i.e. the web app) --> Select the task (most likely loadEnvironmentConfiguration) --> set the script parameters such as -Penv=Development, hit OK
  3. Move this to before the Build Gradle function (by using the up arrow - to the right of + sign you hit in step 2)
like image 526
labheshr Avatar asked Oct 26 '15 19:10

labheshr


People also ask

How do I run Gradle commands in IntelliJ?

From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. icon. In the list that opens, select Run Gradle task. In the Select Gradle Task dialog, specify the project and the task that you want to execute before launching the project.

Where is Gradle settings in IntelliJ?

We can get to the settings from the Gradle Tool Window, or from the usual Settings/Preferences dialog (⌘, (macOS), or Ctrl+Alt+S (Windows/Linux)) and navigating to Build, Execution, Deployment | Build Tools | Gradle.


1 Answers

It seems, that you need to create your specific run or debug configuration. You can read about it in official IntelliJ Idea help. All you need, is to modify your configuration for the task you need, by providing the argument -Penv=Development, since it is running with gradle.

You may also need to define Gradle instance, which will be used via settings, if the defaul wrapper wont work for you. You can find almost all you need in the the official help.

like image 137
Stanislav Avatar answered Oct 18 '22 11:10

Stanislav