如何检查和访问javadoc/source的Maven工件 [英] How to check and access javadoc/source for Maven Artifacts

查看:127
本文介绍了如何检查和访问javadoc/source的Maven工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Maven插件,该插件需要检查某个项目 依赖项具有javadocs和可用的源...如果是这样,想 来下载它们并将其存档在服务器上.

I am writing a Maven plugin which needs to check if a certain project dependency has javadocs and sources available... and if so, would like to download them and archive them on a server.

我无法找到如何检查javadocs和源文件是否可用 或如何访问它们.

I cannot find out how to check if the javadocs and source are available or how to access them if they are.

任何帮助将不胜感激.

推荐答案

您可以通过将 classifier 标记添加到依赖项来引用其他工件.分类器是存储库中工件名称的附加部分,例如junit-4.5- sources .jar

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

因此,要直接声明对junit源jar的依赖关系,可以按如下所示进行指定:

So to directly declare a dependency on the junit sources jar you can specify it as follows:

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

如果要下载所有依赖项源,请使用maven-dependency-plugin的复制依赖项目标指定分类器源.以下示例定义了两个执行,一个用于源代码,一个用于javadocs.

If you want to download all the dependency sources, use the maven-dependency-plugin's copy-dependencies goal specifying the classifier sources. The following example defines two executions, one for sources and one for 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目录:

If you want to package all the downloaded artifacts into a zip, you can use the maven-assembly-plugin to create an archive of the project. The example below are the contents of an assembly descriptor file to include the sources and javadocs directories:

<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中(确保在上面的依赖项配置之后定义了它):

To reference the assembly, add a plugin configuration to your pom. This assumes the above contents have been put in src/main/assembly/sources.xml (make sure it is defined after the dependency configuration above):

<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>

这篇关于如何检查和访问javadoc/source的Maven工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆