diff --git a/core/src/main/java/hudson/tasks/Maven.java b/core/src/main/java/hudson/tasks/Maven.java index bfbe981143b03e1f6cd75c8fe02bebb6b4681b59..c2ebbafafbaeb415ca30de1534ca7d3892476ad6 100644 --- a/core/src/main/java/hudson/tasks/Maven.java +++ b/core/src/main/java/hudson/tasks/Maven.java @@ -98,26 +98,49 @@ public class Maven extends Builder { */ public final String properties; + /** + * If true, the build will use its own local Maven repository + * via "-Dmaven.repo.local=...". + *
+ * 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.
+ *
+ * Identical to logic used in maven-plugin.
+ *
+ * @since 1.322
+ */
+ public boolean usePrivateRepository = false;
+
private final static String MAVEN_1_INSTALLATION_COMMON_FILE = "bin/maven";
private final static String MAVEN_2_INSTALLATION_COMMON_FILE = "bin/mvn";
public Maven(String targets,String name) {
- this(targets,name,null,null,null);
+ this(targets,name,null,null,null,false);
}
@DataBoundConstructor
- public Maven(String targets,String name, String pom, String properties, String jvmOptions) {
+ public Maven(String targets,String name, String pom, String properties, String jvmOptions, boolean usePrivateRepository) {
this.targets = targets;
this.mavenName = name;
this.pom = Util.fixEmptyAndTrim(pom);
this.properties = Util.fixEmptyAndTrim(properties);
this.jvmOptions = Util.fixEmptyAndTrim(jvmOptions);
+ this.usePrivateRepository = usePrivateRepository;
}
public String getTargets() {
return targets;
}
+ public void setUsePrivateRepository(boolean usePrivateRepository) {
+ this.usePrivateRepository = usePrivateRepository;
+ }
+
+ public boolean usesPrivateRepository() {
+ return usePrivateRepository;
+ }
+
/**
* Gets the Maven to invoke,
* or null to invoke the default one.
@@ -221,6 +244,8 @@ public class Maven extends Builder {
args.add("-f",pom);
args.addKeyValuePairs("-D",build.getBuildVariables());
args.addKeyValuePairsFromPropertyString("-D",properties,vr);
+ if(usesPrivateRepository())
+ args.add("-Dmaven.repo.local="+build.getWorkspace().child(".repository"));
args.addTokenized(normalizedTarget);
if(mi!=null) {
diff --git a/core/src/main/resources/hudson/tasks/Maven/config.jelly b/core/src/main/resources/hudson/tasks/Maven/config.jelly
index 10f0f974bb71139c4a03af58bd03b551de7db66c..5229ab396c78032d303f9afd57844a9371fa9b0a 100644
--- a/core/src/main/resources/hudson/tasks/Maven/config.jelly
+++ b/core/src/main/resources/hudson/tasks/Maven/config.jelly
@@ -46,5 +46,8 @@ THE SOFTWARE.