Index: lucene/common-build.xml
===================================================================
--- lucene/common-build.xml	(revision 1397026)
+++ lucene/common-build.xml	(working copy)
@@ -178,6 +178,7 @@
   <makeurl file="${maven.dist.dir}" property="m2.repository.url" validate="false"/>
   <property name="m2.repository.private.key" value="${user.home}/.ssh/id_dsa"/>
   <property name="m2.repository.id" value="local"/>
+  <property name="m2.credentials.prompt" value="true"/>
 
   <property name="jflex.home" location="${common.dir}"/>
 
@@ -435,14 +436,19 @@
 
   <macrodef name="m2-deploy" description="Builds a Maven artifact">
   	<element name="artifact-attachments" optional="yes"/>
+    <element name="local-repository" optional="yes"/>
+    <element name="credentials" optional="yes"/>
     <attribute name="pom.xml"/>
     <attribute name="jar.file" default="${build.dir}/${final.name}.jar"/>
     <sequential>
       <artifact:install-provider artifactId="wagon-ssh" version="1.0-beta-7"/>
       <artifact:pom id="maven.project" file="@{pom.xml}"/>
       <artifact:deploy file="@{jar.file}">
+        <local-repository/>
+        <remoteRepository id="${m2.repository.id}" url="${m2.repository.url}">
+          <credentials/>
+        </remoteRepository>
         <artifact-attachments/>
-      	<remoteRepository id="${m2.repository.id}" url="${m2.repository.url}"/>
         <pom refid="maven.project"/>
       </artifact:deploy>
     </sequential>
@@ -1357,6 +1363,9 @@
         <arg value="${maven.dist.dir}"/>              <!-- Maven distribution artifacts directory -->
         <arg value="${output.build.xml}"/>            <!-- Ant build file to be written -->
         <arg value="${common.dir}/common-build.xml"/> <!-- Imported from the ant file to be written -->
+        <arg value="${m2.credentials.prompt}"/>
+        <arg value="${m2.repository.id}"/>
+        <arg value="${m2.repository.url}"/>
       </exec>
       <echo message="${stage.maven.script.output}"/>
     </sequential>
Index: dev-tools/scripts/write.stage.maven.build.xml.pl
===================================================================
--- dev-tools/scripts/write.stage.maven.build.xml.pl	(revision 1397026)
+++ dev-tools/scripts/write.stage.maven.build.xml.pl	(working copy)
@@ -33,16 +33,26 @@
 use warnings;
 use File::Basename;
 use File::Find;
+use Cwd 'abs_path';
 use File::Path qw(make_path);
 
 my $num_artifacts = 0;
-my $maven_dist_dir = $ARGV[0];
+my $maven_dist_dir = abs_path($ARGV[0]);
 my $output_build_xml_file = $ARGV[1];
 my $common_build_xml = $ARGV[2];
-if ($^O eq 'cygwin') { # Make sure Cygwin Perl can find the output path
+my $prompt_for_credentials = $ARGV[3];
+my $m2_repository_id = $ARGV[4];
+my $m2_repository_url = $ARGV[5];
+my $local_repo_dir = $maven_dist_dir;
+if ($^O eq 'cygwin') {
+  # Make sure Cygwin Perl can find the output path
   $output_build_xml_file = `cygpath -u "$output_build_xml_file"`;
   $output_build_xml_file =~ s/\s+$//; # Trim trailing whitespace
   $output_build_xml_file =~ s/^\s+//; # Trim leading whitespace
+  # Convert local repo dir to Windows path for native Ant
+  $local_repo_dir = `cygpath -w "$local_repo_dir"`;
+  $local_repo_dir =~ s/\s+$//;
+  $local_repo_dir =~ s/^\s+//;
 }
 my ($output_file, $output_dir) = fileparse($output_build_xml_file);
 make_path($output_dir);
@@ -57,6 +67,21 @@
     <sequential>
 !;
 
+my $credentials = '';
+if ($prompt_for_credentials !~ /\A(?s:f(?:alse)?|no?)\z/ ) {
+  print $output_build_xml qq!
+      <input message="Enter $m2_repository_id username: >" addproperty="m2.repository.username"/>
+      <input message="Enter $m2_repository_id password: >" addproperty="m2.repository.password">
+        <handler type="secure"/>
+      </input>
+!;
+  $credentials =<<'__CREDENTIALS__';
+<credentials>
+          <authentication username="${m2.repository.username}" password="${m2.repository.password}"/>
+        </credentials>
+__CREDENTIALS__
+}
+
 sub wanted;
 
 File::Find::find({follow => 1, wanted => \&wanted}, $maven_dist_dir);
@@ -90,14 +115,21 @@
     if (-f $war_file) {
       print $output_build_xml qq!
       <m2-deploy pom.xml="${pom_file}" jar.file="${war_file}">
+        <local-repository>
+          <localRepository path="$local_repo_dir"/>
+        </local-repository>
         <artifact-attachments>
           <attach file="${pom_file}.asc" type="pom.asc"/>
           <attach file="${war_file}.asc" type="war.asc"/>
         </artifact-attachments>
+        $credentials
       </m2-deploy>\n!;
     } elsif (-f $jar_file) {
       print $output_build_xml qq!
       <m2-deploy pom.xml="${pom_file}" jar.file="${jar_file}">
+        <local-repository>
+          <localRepository path="$local_repo_dir"/>
+        </local-repository>
         <artifact-attachments>
           <attach file="${basepath}-sources.jar" classifier="sources"/>
           <attach file="${basepath}-javadoc.jar" classifier="javadoc"/>
@@ -106,13 +138,18 @@
           <attach file="${basepath}-sources.jar.asc" classifier="sources" type="jar.asc"/>
           <attach file="${basepath}-javadoc.jar.asc" classifier="javadoc" type="jar.asc"/>
         </artifact-attachments>
+        $credentials
       </m2-deploy>\n!;
     } else {
       print $output_build_xml qq!
       <m2-deploy pom.xml="${pom_file}">
+        <local-repository>
+          <localRepository path="$local_repo_dir"/>
+        </local-repository>
         <artifact-attachments>
           <attach file="${pom_file}.asc" type="pom.asc"/>
         </artifact-attachments>
+        $credentials
       </m2-deploy>\n!;
     }
 
