diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java index f8ec1162..02a1ff99 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java @@ -221,23 +221,14 @@ protected String getClassifier() { * @throws IOException {@link IOException} */ private File generateArchive(File javadocFiles, String jarFileName) throws ArchiverException, IOException { - File javadocJar = new File(jarOutputDirectory, jarFileName); - - if (javadocJar.exists()) { - javadocJar.delete(); - } - MavenArchiver archiver = new MavenArchiver(); - archiver.setCreatedBy("Maven Javadoc Plugin", "org.apache.maven.plugins", "maven-javadoc-plugin"); archiver.setArchiver(jarArchiver); - archiver.setOutputFile(javadocJar); + archiver.setCreatedBy("Maven Javadoc Plugin", "org.apache.maven.plugins", "maven-javadoc-plugin"); // configure for Reproducible Builds based on outputTimestamp value archiver.configureReproducibleBuild(outputTimestamp); - if (!javadocFiles.exists()) { - getLog().warn("JAR will be empty - no content was marked for inclusion!"); - } else { + if (javadocFiles.exists()) { archiver.getArchiver().addDirectory(javadocFiles, DEFAULT_INCLUDES, DEFAULT_EXCLUDES); } @@ -254,14 +245,20 @@ private File generateArchive(File javadocFiles, String jarFileName) throws Archi archive.setManifestFile(defaultManifestFile); } + File outputFile = new File(jarOutputDirectory, jarFileName); + + // Why do we do this? + if (outputFile.exists()) { + outputFile.delete(); + } + archiver.setOutputFile(outputFile); + try { archiver.createArchive(session, project, archive); - } catch (ManifestException e) { - throw new ArchiverException("ManifestException: " + e.getMessage(), e); - } catch (DependencyResolutionRequiredException e) { - throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e); + } catch (ManifestException | DependencyResolutionRequiredException e) { + throw new ArchiverException("Error creating Javadoc archive: " + e.getMessage(), e); } - return javadocJar; + return outputFile; } }