I have configured the enforcer to check for some properties. These are exported as environment variables in my .profile
file in my home dir. The build from the console runs fine.
The build from intellij (doubleclicking the goals in the maven menu) fails, as enforcer cannot find the properties...What is going wrong here and how to fix it?
My first guess is that intellij is running maven as a different user but I'm not sure how to verify it or what to do about it.
NOTE: I am not asking for a workaround. One would be to set the properties in maven Runner settings of intellij, a second - to set the properties in /etc/profile
. But I would like to avoid them.
EDIT : I have tried restarting intellij, the X server and the machine - to no effect on the enforcer. printenv
in a fresh console shows my variables as expected. Starting intellij from the same console leads to the same build failure.
Thank you.
Each program has its own environment. If you change the environment settings in .profile
or the like, it doesn't change the setting for running programs. When one program runs another program it inherits the settings/environment of its parent. It doesn't load the settings again.
What you could be finding is that changes you make after IntelliJ has started, have no effect from programs IntelliJ runs. The same thing would happen if you opened a command window, changed the settings and run a new programs (the shell would keep the settings it had when it started) To fix this you need to re-start IntelliJ. If you run it from the command line, make sure its a new window.
This unit test should dump the environment.
@Test
public void dumpEnv() {
for (Map.Entry<String, String> entry : new TreeMap<String, String>(System.getenv()).entrySet()) {
System.out.println(entry);
}
}
.profile
is only executed when you log on using KSH. If you use BASH, it has no effect.
.bashrc
(if you use BASH) is a much more suitable place because it's executed every time you start a shell (shell scripts, new terminal windows, etc).
For KSH, .kshrc
has the same effect .
To make sure the variables are there, use set
(no options) to list all of them or set|grep
pattern to search. As soon as they show up in a new terminal window, they should be there from inside your IDE, too.
[EDIT] If set
can see them, so can IntelliJ. The only thing left is that IntelliJ could clean the environment when it starts Maven.
To test that, rename mvn
to mvn.orig
and create a new script mvn
with this content:
#!/bin/bash
set > $HOME/mvn_env.log
mvn.orig "$@"
This script dumps the environment as mvn
sees it to $HOME/mvn_env.log
. If the variables are missing, then IntelliJ cleans the environment.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.