diff --git a/core/src/main/java/hudson/maven/MavenBuild.java b/core/src/main/java/hudson/maven/MavenBuild.java index 56fc2e03b0427b9c22f66b5ab45e367fb3ec75e8..a1c01cc5a132f28c5dbb9eecfc95a4e536a1d89b 100644 --- a/core/src/main/java/hudson/maven/MavenBuild.java +++ b/core/src/main/java/hudson/maven/MavenBuild.java @@ -420,7 +420,12 @@ public class MavenBuild extends AbstractBuild { 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 systemProps = new HashMap(envVars); diff --git a/core/src/main/java/hudson/maven/MavenModuleSet.java b/core/src/main/java/hudson/maven/MavenModuleSet.java index 69ab5a89f8863c2a0481391ca748a4f8587b15ac..f1bfee4cd313e268a9813e187e301492cbdeda8a 100644 --- a/core/src/main/java/hudson/maven/MavenModuleSet.java +++ b/core/src/main/java/hudson/maven/MavenModuleSet.java @@ -81,6 +81,18 @@ public final class MavenModuleSet extends AbstractMavenProject + * 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 + diff --git a/war/resources/help/maven/private-repository.html b/war/resources/help/maven/private-repository.html new file mode 100644 index 0000000000000000000000000000000000000000..3d11a12710a28a69c032746ce3ea7572dae7e6c6 --- /dev/null +++ b/war/resources/help/maven/private-repository.html @@ -0,0 +1,26 @@ +
+ Normally, Hudson uses the local Maven repository as determined by Maven — the exact process + seems to be undocumented, but it's ~/.m2/repository and can be overridden by + <localRepository> in ~/.m2/settings.xml (see the reference for more details.) + +

+ 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. + +

+ There are also some reported problems regarding having concurrent Maven processes trying to use the same local + repository. + + +

+ When this option is checked, Hudson will tell Maven to use $WORKSPACE/.repository 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. + +

+ When using this option, consider setting up a Maven artifact manager so that you don't have to hit + remote Maven repositories too often. +

\ No newline at end of file