public static void write(Set<Artifact> artifacts, String targetDirectory) throws MojoExecutionException {
RepositoryLayout m2layout = new MavenDefaultLayout();
for (Artifact artifact : artifacts) {
File src = artifact.getFile();
artifact = artifact.setVersion(artifact.getBaseVersion());
File dest = new File(targetDirectory, m2layout.getPath(artifact).getPath());
try {
System.out.println("Copying " + src + " to " + dest);
FileUtils.copyFile(src, dest);
} catch (IOException e) {
throw new MojoExecutionException("Error copying file " + src + " to " + dest);
}
File srcPom = pomFile(src);
File destPom = pomFile(dest);
if (srcPom != null && srcPom.exists()) {
try {
FileUtils.copyFile(srcPom, destPom);
} catch (IOException e) {
throw new MojoExecutionException("Error copying file " + srcPom + " to " + destPom);
}
}
}
}