mirror of https://github.com/apache/maven.git
use MVNW_USER and MVNW_PASSWORD instead of system properties
fix distribution naming add readme entry
This commit is contained in:
parent
e9d72b79f6
commit
ffc8cc20ca
maven-wrapper
|
@ -102,6 +102,19 @@ which works for any version except snapshots. Once you have a wrapper you can ch
|
|||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
|
||||
```
|
||||
|
||||
## Using Basic Authentication for Distribution download
|
||||
|
||||
To download Maven from a location that requires Basic Authentication you have 2 options:
|
||||
|
||||
1. Set the environment variables MVNW_USER and MVNW_PASSWORD
|
||||
|
||||
or
|
||||
|
||||
2. add user and password to the distributionUrl like that:
|
||||
`distributionUrl=https://username:password@<yourserver>/maven2/org/apache/maven/apache-maven/3.2.1/apache-maven-3.2.1-bin.zip`
|
||||
|
||||
|
||||
|
||||
[1]: https://github.com/takari/takari-maven-plugin
|
||||
|
||||
## Specifying Maven Distribution Base Path
|
||||
|
|
|
@ -16,9 +16,21 @@
|
|||
|
||||
package org.apache.maven.wrapper;
|
||||
|
||||
import java.io.*;
|
||||
import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_PASSWORD;
|
||||
import static org.apache.maven.wrapper.MavenWrapperMain.MVNW_USER;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.*;
|
||||
import java.net.Authenticator;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* @author Hans Dockter
|
||||
|
@ -104,7 +116,7 @@ public class DefaultDownloader implements Downloader {
|
|||
return;
|
||||
}
|
||||
if (!"https".equals(address.getScheme())) {
|
||||
Logger.info("WARNING Using HTTP Basic Authentication over an insecure connection to download the Gradle distribution. Please consider using HTTPS.");
|
||||
Logger.info("WARNING Using HTTP Basic Authentication over an insecure connection to download the Maven distribution. Please consider using HTTPS.");
|
||||
}
|
||||
connection.setRequestProperty("Authorization", "Basic " + base64Encode(userInfo));
|
||||
}
|
||||
|
@ -132,14 +144,14 @@ public class DefaultDownloader implements Downloader {
|
|||
Method encodeMethod = loader.loadClass("javax.xml.bind.DatatypeConverter").getMethod("printBase64Binary", byte[].class);
|
||||
return (String) encodeMethod.invoke(null, new Object[]{userInfo.getBytes("UTF-8")});
|
||||
} catch (Exception java5OrEarlier) {
|
||||
throw new RuntimeException("Downloading Gradle distributions with HTTP Basic Authentication is not supported on your JVM.", java5OrEarlier);
|
||||
throw new RuntimeException("Downloading Maven distributions with HTTP Basic Authentication is not supported on your JVM.", java5OrEarlier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String calculateUserInfo(URI uri) {
|
||||
String username = System.getProperty("maven.wrapperUser");
|
||||
String password = System.getProperty("maven.wrapperPassword");
|
||||
String username = System.getenv(MVNW_USER);
|
||||
String password = System.getenv(MVNW_PASSWORD);
|
||||
if (username != null && password != null) {
|
||||
return username + ':' + password;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,9 @@ public class MavenWrapperMain {
|
|||
public static final String MAVEN_USER_HOME_ENV_KEY = "MAVEN_USER_HOME";
|
||||
|
||||
public static final String MVNW_VERBOSE = "MVNW_VERBOSE";
|
||||
public static final String MVNW_USER = "MVNW_USER";
|
||||
public static final String MVNW_PASSWORD = "MVNW_PASSWORD";
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
File wrapperJar = wrapperJar();
|
||||
|
|
Loading…
Reference in New Issue