如何检查和访问javadoc/source的Maven工件

编程入门 行业动态 更新时间:2024-10-26 01:16:38
本文介绍了如何检查和访问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工件

本文发布于:2023-11-25 02:35:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工件   javadoc   source   Maven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!