Skip to content

Commit

Permalink
[FIXED JENKINS-8092]
Browse files Browse the repository at this point in the history
Set M2_Home for maven builds and add maven to the path so if the build
needs to run maven from maven (or maven from ant from maven) it can.

Originally-Committed-As: b0b06b515ba4471a1ec6fec77d96efc71935b2b9
  • Loading branch information
jtnord committed Feb 20, 2011
1 parent 8fa1e5f commit 4e6dd1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/hudson/maven/MavenBuild.java
Expand Up @@ -193,6 +193,18 @@ public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedE
String opts = project.getParent().getMavenOpts();
if(opts!=null)
envs.put("MAVEN_OPTS", opts);
// We need to add M2_HOME and the mvn binary to the PATH so if Maven
// needs to run Maven it will pick the correct one.
// This can happen if maven calls ANT which itself calls Maven
// or if Maven calls itself e.g. maven-release-plugin
MavenInstallation mvn = project.getParent().getMaven();
if (mvn == null)
throw new AbortException(
"A Maven installation needs to be available for this project to be built.\n"
+ "Either your server has no Maven installations defined, or the requested Maven version does not exist.");
mvn = mvn.forEnvironment(envs).forNode(Computer.currentComputer().getNode(), log);
envs.put("M2_HOME", mvn.getHome());
envs.put("PATH+MAVEN", mvn.getHome() + "/bin");
return envs;
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/hudson/maven/MavenModuleSetBuild.java
Expand Up @@ -147,6 +147,20 @@ public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedE
String opts = project.getMavenOpts();
if(opts!=null)
envs.put("MAVEN_OPTS", opts);
// We need to add M2_HOME and the mvn binary to the PATH so if Maven
// needs to run Maven it will pick the correct one.
// This can happen if maven calls ANT which itself calls Maven
// or if Maven calls itself e.g. maven-release-plugin
MavenInstallation mvn = project.getMaven();
if (mvn == null)
throw new AbortException(
"A Maven installation needs to be available for this project to be built.\n"
+ "Either your server has no Maven installations defined, or the requested Maven version does not exist.");

mvn = mvn.forEnvironment(envs).forNode(
Computer.currentComputer().getNode(), log);
envs.put("M2_HOME", mvn.getHome());
envs.put("PATH+MAVEN", mvn.getHome() + "/bin");
return envs;
}

Expand Down

0 comments on commit 4e6dd1d

Please sign in to comment.