Variables for Run/Debug Configurations
已回答
I've noticed that the run/debug configurations refer to $PROJECT_DIR to find the executable. Are other variables available?
In particular, I have a project structure like this, with multiple git repos grouped together so that I don't have to switch windows:
$PROJECT_DIR
|__ git_repo1
| |__ .run
| |__ build
| |__ libs (jar files here)
|__ git_repo2
| |__ .run
| |__ build
| |__ libs (jar files here)
I would like to the run/debug configuration stored in `git_repo1/.run` to refer to the jar files for git_repo1 relative to the *.run.xml file's location (i.e. relative to `git_repo1/.run`). The default of $PROJECT_DIR it looks like this:
<component name="ProjectRunConfigurationManager">
<configuration default="false" ...>
<ExternalSystemSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$/git_repo1/build/libs/my.jar" />
Could I have something like this instead?
<component name="ProjectRunConfigurationManager">
<configuration default="false" ...>
<ExternalSystemSettings>
<option name="externalProjectPath" value="$RUN_DIR$/../build/libs/my.jar" />
If not, then the run/debug configuration will not work if I check out git_repo1 on its own.
请先登录再写评论。
Please see https://www.jetbrains.com/help/idea/absolute-path-variables.html.
Thanks Serge Baranov, it looks like $MODULE_WORKING_DIR$ is the option I need but when I try it in a Gradle configuration, setting the `Gradle project` to
I get this error when running:
I tried it in IntelliJ IDEA 2020.3.4 and 2021.2.3.
@John Green could you please show screenshot of your run configuration and how you use the
$MODULE_WORKING_DIR$macro and how it was used before the error? Also please attach screenshot of IDE Gradle settings and idea.log file (use Help | Show Log in ... action) after IDE restart. For uploading you can use https://uploads.jetbrains.com or any file sharing service. Thank you.
Andrey Dernov, thank you for looking at this further. I looked at idea.log and it's not showing much so I've made a simple project that displays the problem and uploaded it to Upload id: 2021_11_25_Mjfi8eSNgsk9U4Pw (file: run-config-test.zip)
This contains a repo similar to the one I've described above, except that I've used SpringBoot - it's a bit closer to my actual project.
A little bit more about the underlying problem. I have two git repos which I would like to open in the same IntelliJ window so that I can do diffs, and edit them without swapping windows. However, sometimes it's nicer to open each git repo individually - when I do that the run configurations don't work anymore because $PROJECT_DIR$ has changed to a different place. With the grouped projects (as in the zip), the externalProjectPath is `$PROJECT_DIR$/repo1` but with a single repo at a time, it has to be `$PROJECT_DIR$` only.
Here are some images as well, in case it helps others to try this:
Not working:
Thanks. The problem with using the $MODULE_WORKING_DIR$ is that it is not clear what module should it be. As it is not specified anywhere else. But the $PROJECT_DIR path not ambiguous in this sense.
You can define two Path Variables for these two module paths for each run configuration, e.g.
- My_Module_1 for <absolute path to project>/git_repo1
- My_Module_2 for <absolute path to project>/git_repo2
After you define them - IDE should automatically use them in xml file paths when saving your Run Configurations.
Or please use different run configurations that would be specific to each project configuration.
Btw explicitly specifying path macros in the UI is not expected. One should just define the Path Variables in the IDE settings - IDE will automatically use them in config xml files for these paths.
Hi Andrey Dernov, I think the two Path Variables will be the best option in my case. I had hoped that $MODULE_WORKING_DIR$ would refer to the module that the *.run.xml file was in, but maybe that is too complex for a general solution.
Thank you for your help!
Hello Andrey Dernov
We are facing the exact same problem in our team.
We would like to share run configurations between people, but some are working in a single module intellij while other works in multi modules intellij.
If we use $PROJECT_DIR$/repo1 in our run configuration, people working on single-module intellij cannot use them as the path is not valid
Defining a path variable for each module (such as My_Module_1 for <absolute path to project>/git_repo1) is not an option for us as we have 40+ modules.
It would be very helpful to have a path variable that resolves automatically to the module in which the run configuration xml is in.
Hi @Leo
Are you using the same type of run configurations as the OP (Gradle)?
Hello @...
No we are using maven deployment and DockerFile deployment, but the problem is the same
>It would be very helpful to have a path variable that resolves automatically to the module in which the run configuration xml is in.
>No we are using maven deployment and DockerFile deployment, but the problem is the same
The initially described problem is specific to Gradle run configuration - because module directory is not used in Gradle run configuration anywhere.
Actually, Docker and Maven run configurations are also are not bound to any module - so there is no way to understand for which modules they are launched.