0

Hoping someone can explain how to set the plugin options correctly.

I am looking to have a pom file that someone could execute an mvn command on to download all the jars of the dependencies (transitive included) defined in the pom (including their sources and javadoc jars) from Maven Central and copy them to a specified directory.

My question appears quite similar to maven-dependency-plugin ignores outputDirectory configuration but dwells on a slightly different aspect. Tried the approach advised in the accepted answer there but that didn't work.

pom file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>gq.jetstream</groupId>
    <artifactId>maven-download-sources-javadocs</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <org.springframework.version>5.2.22.RELEASE</org.springframework.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    </dependencies>
    <build>
        <!-- <sourceDirectory>src</sourceDirectory> -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.3.0</version>

                <executions>
                   <execution>
                     <id>copy-dependencies</id>
                     <phase>package</phase>
                     <goals>
                       <goal>copy-dependencies</goal>
                     </goals>
                     <configuration>
                       <includeScope>runtime</includeScope>
                       <classifier>sources</classifier>
                       <classifier>javadoc</classifier>
                       <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
                       <includeClassifiers>sources,javadoc</includeClassifiers>
                     </configuration>
                   </execution>
                </executions>
              </plugin>
        </plugins>
     </build>
</project>

Executing mvn package against this pom doesn't do anything. The output for the goal execution was empty.

Alt 1: Tried the following command. This copied the javadoc jars only and not the binary jars and sources jars of the dependencies.

mvn dependency:copy-dependencies@copy-dependencies
[INFO] Scanning for projects...
[INFO]
[INFO] ------------< gq.jetstream:maven-download-sources-javadocs >------------
[INFO] Building maven-download-sources-javadocs 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.3.0:copy-dependencies (copy-dependencies) @ maven-download-sources-javadocs ---
[INFO] Copying spring-core-5.2.22.RELEASE-javadoc.jar to C:\projects\code\maven-download-sources-javadocs\target\dependency-jars\spring-core-5.2.22.RELEASE-javadoc.jar
[INFO] Copying spring-jcl-5.2.22.RELEASE-javadoc.jar to C:\projects\code\maven-download-sources-javadocs\target\dependency-jars\spring-jcl-5.2.22.RELEASE-javadoc.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.846 s
[INFO] Finished at: 2022-06-22T02:09:55+01:00
[INFO] ------------------------------------------------------------------------
JetStream
  • 518
  • 2
  • 6
  • 17
  • Why do you like to copy them to a directory instead of using them? The download is usually simply done by building the project... and most of the time people use a repository manager ... ? – khmarbaise Jun 22 '22 at 07:02
  • BTW: Why have you configured that: `src` ??? – khmarbaise Jun 22 '22 at 07:19
  • We have an environment that is not connected to the internet. We are looking to use this mechanism to enable junior staff to download the jars specified in the pom in one place before copying them using a USB drive to the internal Nexus repo @khmarbaise – JetStream Jun 23 '22 at 08:35
  • Apologies. `src` is not necessary. I'll remove that. – JetStream Jun 23 '22 at 08:38
  • That sounds a bit strange to be honest... `jars specified in the pom in one place before copying them using a USB drive to the internal Nexus repo` if you have already a repository manager why is that repo manager not connected to the internet to provide the things you need ... the usage etc. can be controlled by Nexus... The simplest thing I could think of is using the build which downloads all needed thigns and calling `mvn dependency:sources (https://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html) to get sources... the javadoc is most of the time not needed. – khmarbaise Jun 23 '22 at 08:45
  • I understand where you are coming from, but unfortunately, this is necessaitated because the application environments are air-gapped due to various rules. – JetStream Jun 23 '22 at 11:12

0 Answers0