提交 b0b06b51 编写于 作者: J James Nord

[FIXED JENKINS-8092]

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.
上级 1908a88b
......@@ -72,6 +72,9 @@ Upcoming changes</a>
<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=-->
......
......@@ -193,6 +193,18 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
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;
}
......
......@@ -147,6 +147,20 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册