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.
  • Loading branch information
jtnord committed Feb 20, 2011
1 parent 1908a88 commit b0b06b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -72,6 +72,9 @@
<li class=rfe>
Allow classworlds.conf to be externally configured for M3 builds
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-8905">issue 8905</a>)
<li class=bug>
Configure the environment for Maven job type builds
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-8092">issue 8902</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
12 changes: 12 additions & 0 deletions maven-plugin/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 maven-plugin/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 b0b06b5

Please sign in to comment.