in src/main/java/org/apache/maven/shared/archiver/MavenArchiver.java [502:576]
public void doCreateArchive(Session session, Project project, MavenArchiveConfiguration archiveConfiguration)
throws ManifestException, IOException {
// we have to clone the project instance so we can write out the pom with the deployment version,
// without impacting the main project instance...
boolean forced = archiveConfiguration.isForced();
if (archiveConfiguration.isAddMavenDescriptor()) {
// ----------------------------------------------------------------------
// We want to add the metadata for the project to the JAR in two forms:
//
// The first form is that of the POM itself. Applications that wish to
// access the POM for an artifact using maven tools they can.
//
// The second form is that of a properties file containing the basic
// top-level POM elements so that applications that wish to access
// POM information without the use of maven tools can do so.
// ----------------------------------------------------------------------
String groupId = project.getGroupId();
String artifactId = project.getArtifactId();
String version;
if (project.getPomArtifact().isSnapshot()) {
version = project.getPomArtifact().getVersion().toString();
} else {
version = project.getVersion();
}
archiver.addFile(
project.getPomPath().toFile(), "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml");
// ----------------------------------------------------------------------
// Create pom.properties file
// ----------------------------------------------------------------------
Path customPomPropertiesFile = archiveConfiguration.getPomPropertiesFile();
Path dir = Paths.get(project.getBuild().getDirectory(), "maven-archiver");
Path pomPropertiesFile = dir.resolve("pom.properties");
new PomPropertiesUtil()
.createPomProperties(
groupId, artifactId, version, archiver, customPomPropertiesFile, pomPropertiesFile);
}
// ----------------------------------------------------------------------
// Create the manifest
// ----------------------------------------------------------------------
archiver.setMinimalDefaultManifest(true);
Path manifestFile = archiveConfiguration.getManifestFile();
if (manifestFile != null) {
archiver.setManifest(manifestFile.toFile());
}
Manifest manifest = getManifest(session, project, archiveConfiguration);
// Configure the jar
archiver.addConfiguredManifest(manifest);
archiver.setCompress(archiveConfiguration.isCompress());
archiver.setRecompressAddedZips(archiveConfiguration.isRecompressAddedZips());
archiver.setDestFile(archiveFile);
archiver.setForced(forced);
if (!archiveConfiguration.isForced() && archiver.isSupportingForced()) {
// TODO Should issue a warning here, but how do we get a logger?
// TODO getLog().warn(
// "Forced build is disabled, but disabling the forced mode isn't supported by the archiver." );
}
String automaticModuleName = manifest.getMainSection().getAttributeValue("Automatic-Module-Name");
if (automaticModuleName != null) {
if (!isValidModuleName(automaticModuleName)) {
throw new ManifestException("Invalid automatic module name: '" + automaticModuleName + "'");
}
}
// create archive
archiver.createArchive();
}