@Override
public void execute() throws MojoExecutionException, MojoFailureException {
File localRepository = new File(System.getProperty("user.home"), ".m2/repository");
String artifactPath = String.format("io/takari/maven-wrapper/%s/maven-wrapper-%s.tar.gz", version, version);
String wrapperUrl = String.format("https://repo1.maven.org/maven2/%s", artifactPath);
File destination = new File(localRepository, artifactPath);
Downloader downloader = new DefaultDownloader("mvnw", version);
try {
downloader.download(new URI(wrapperUrl), destination);
UnArchiver unarchiver = UnArchiver.builder().useRoot(false).build();
Path rootDirectory = Paths.get(session.getExecutionRootDirectory());
unarchiver.unarchive(destination, rootDirectory.toFile());
overwriteDistributionUrl(rootDirectory, getDistributionUrl());
getLog().info("");
getLog().info("The Maven Wrapper version " + version + " has been successfully setup for your project.");
getLog().info("Using Apache Maven " + maven);
getLog().info("");
} catch (Exception e) {
throw new MojoExecutionException("Error installing the maven-wrapper archive.", e);
}
}