How to check and access javadoc / source for Maven artifacts

I am writing a Maven plugin which should check if some kind of dependency project is working, has javadocs and sources available ... and if so, I would like to download and archive them on the server.

I can’t find out how to check if javadocs and the source are available or how to access them, if any.

Any help would be appreciated.

+3
source share
1 answer

You can reference additional artifacts by adding a classifier tag to the dependency. The classifier is an additional part of the artifact name in the repository, for example junit-4.5-sources.jar

, junit- jar, :

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.5</version>
  <classifier>sources</classifier>
  <scope>test</scope>
</dependency>

, - maven-dependency-plugin, . : javadocs.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>sources</id>
          <phase>package</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <classifier>sources</classifier>
            <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
            <outputDirectory>${project.build.directory}/sources</outputDirectory>
          </configuration>
        </execution>
        <execution>
          <id>javadocs</id>
          <phase>package</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <classifier>javadoc</classifier>
            <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
            <outputDirectory>${project.build.directory}/javadocs</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

zip, maven-assembly-plugin . , javadocs:

<assembly>
  <id>project</id>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}</directory>
      <useDefaultExcludes>true</useDefaultExcludes>
      <includes>
        <include>${project.build.directory}/sources</include>
        <include>${project.build.directory}/javadocs</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

, pom. , src/main/assembly/sources.xml(, ):

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-4</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptors>
           <descriptor>src/main/assembly/sources.xml</descriptor>
        </descriptors>
      </configuration>
    </execution>
  </executions>
</plugin>
+3

Source: https://habr.com/ru/post/1713714/


All Articles