提交 f95e2929 编写于 作者: K kohsuke

Maven jobs can be now executed with its own private local Maven repository for better isolation.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10023 71c3de6d-444a-0410-be80-ed276b4c234a
上级 5f25e2e1
......@@ -420,7 +420,12 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> {
ArgumentListBuilder margs = new ArgumentListBuilder();
margs.add("-N").add("-B");
margs.add("-f",getParent().getModuleRoot().child("pom.xml").getRemote());
MavenModuleSet mms = project.getParent();
if(mms.usesPrivateRepository())
// use the per-project repository. should it be per-module? But that would cost too much in terms of disk
// the workspace must be on this node, so getRemote() is safe.
margs.add("-D").add("maven.repo.local="+mms.getWorkspace().child(".repository").getRemote());
margs.add("-f",getProject().getModuleRoot().child("pom.xml").getRemote());
margs.addTokenized(getProject().getGoals());
Map<String,String> systemProps = new HashMap<String, String>(envVars);
......
......@@ -81,6 +81,18 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
*/
private boolean aggregatorStyleBuild = true;
/**
* If true, the build will use its own local Maven repository
* via "-Dmaven.repo.local=...".
* <p>
* This would consume additional disk space, but provides isolation with other builds on the same machine,
* such as mixing SNAPSHOTS. Maven also doesn't try to coordinate the concurrent access to Maven repositories
* from multiple Maven process, so this helps there too.
*
* @sine 1.223
*/
private boolean usePrivateRepository = false;
/**
* Reporters configured at {@link MavenModuleSet} level. Applies to all {@link MavenModule} builds.
*/
......@@ -211,6 +223,10 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
return aggregatorStyleBuild;
}
public boolean usesPrivateRepository() {
return usePrivateRepository;
}
/**
* List of active {@link MavenReporter}s that should be applied to all module builds.
*/
......@@ -500,7 +516,8 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
goals = Util.fixEmpty(req.getParameter("goals").trim());
mavenOpts = Util.fixEmpty(req.getParameter("mavenOpts").trim());
mavenName = req.getParameter("maven_version");
aggregatorStyleBuild = req.getParameter("maven.perModuleBuild")==null;
aggregatorStyleBuild = !req.hasParameter("maven.perModuleBuild");
usePrivateRepository = req.hasParameter("maven.usePrivateRepository");
JSONObject json = StructuredForm.get(req);
reporters.rebuild(req,json,MavenReporters.getConfigurableList(),"reporter");
......
......@@ -318,6 +318,8 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
ArgumentListBuilder margs = new ArgumentListBuilder();
margs.add("-B").add("-f", pom.getRemote());
if(project.usesPrivateRepository())
margs.add("-D").add("maven.repo.local="+project.getWorkspace().child(".repository"));
margs.addTokenized(project.getGoals());
Builder builder = new Builder(slistener, proxies, project.sortedActiveModules, margs.toList(), envVars);
......
......@@ -40,6 +40,8 @@
</f:entry>
<f:optionalBlock name="maven.perModuleBuild" title="${%Build modules in parallel}" help="/help/maven/aggregator.html"
checked="${!it.aggregatorStyleBuild}" />
<f:optionalBlock name="maven.usePrivateRepository" title="${%Use private maven repository}" help="/help/maven/private-repository.html"
checked="${it.usesPrivateRepository()}" />
</f:advanced>
</f:section>
......
<div>
Normally, Hudson uses the local Maven repository as determined by Maven &mdash; the exact process
seems to be undocumented, but it's <tt>~/.m2/repository</tt> and can be overridden by
&lt;localRepository> in <tt>~/.m2/settings.xml</tt> (see <a href="http://maven.apache.org/settings.html">the reference</a> for more details.)
<p>
This normally means that all the jobs that are executed on the same node shares a single Maven repository.
The upside of this is that you can save the disk space, but the downside of this is that sometimes those
builds could interfere with each other. For example, you might end up having builds incorrectly succeed,
just because your have all the dependencies in your local repository, despite that fact that none of the
repositories in POM might have them.
<p>
There are also some reported problems regarding having concurrent Maven processes trying to use the same local
repository.
<p>
When this option is checked, Hudson will tell Maven to use <tt>$WORKSPACE/.repository</tt> as the local Maven repository.
This means each job will get its own isolated Maven repository just for itself. It fixes the above problems,
at the expense of additional disk space consumption.
<p>
When using this option, consider setting up a Maven artifact manager so that you don't have to hit
remote Maven repositories too often.
</div>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册