WestCoastProjects
WestCoastProjects

Reputation: 63162

Are any of the maven goals affected by the operating system environment variables (except MAVEN_OPTS)

We are seeing one developer's laptop is ending up with a testcase failing due to a library versioning mismatch. This happens after the testcases had already run and the uber-jar had been created - but before the installation step.

On several other developer's machines this problem does not happen. One of the team members believes that an environment variable such as HADOOP_CLASSPATH may be at fault.

But .. it was my understanding / concept of the maven approach that builds should run identically across different environments - they are insulated by all environment settings except for JVM ones and maven-specific ones such as MAVEN_OPTS.

Which of the two is correct:

Update Specifically let's focus on the following:

So in other words - the focus here would not be on System.getenv or System.getProperties but on the classpath only.

Upvotes: 1

Views: 60

Answers (2)

bmargulies
bmargulies

Reputation: 100123

Maven does not use a Security Manager to isolate the build completely from the environment. If the build runs code that calls System.getenv, that code will get the value from the environment.

Some Maven plugins that launch new processes provide a means to set environment variable values, but none of them have an option to start from a clean, repeatable, environment.

If you are using the maven-exec-plugin, or any other plugin that launches a new process, and that process is a JVM, that JVM's classpath is indeed modifiable by environment variables or anything else. If you are launching some shell script that launches Hadoop, it will indeed respect whatever environment variables it looks at.

If you are testing code that builds new class loaders, Maven has no influence on what pathnames end up in these classloaders.

It you have code in your unit or integration tests that launches a new JVM, that will have whatever classpath the code arranges. Maven only controls the classpath of Java code run directly from Maven: slightly oversimplified, that is Maven plugins and unit tests.

Upvotes: 1

Gerold Broser
Gerold Broser

Reputation: 14772

Maven exposes environment variables as properties to the build environment. If one of the plugins you use relies on such a property the second of your points can happen. This should be documented on the plugin's doc page.

The Javadoc of the PackMojo class of the hadoop-maven-plugin, for instance, reads:

• The dependencies that are already present in $HADOOP_HOME/lib/*.jar , if present in the project's dependencies are ignored.

Upvotes: 1

Related Questions