简体   繁体   English

Gradle中的自定义依赖关系管理插件

[英]Custom dependency management plugin in Gradle

How do you write a custom gradle plugin to handle dependencies in a custom module descriptor, from a custom repository? 如何编写自定义gradle插件来处理自定义存储库中自定义模块描述符中的依赖项? The gradle documentation says the following, but I haven't been able to find anything that tells me how . gradle文档说明如下,但我找不到任何能告诉我如何做的事情。

Even if your project is using a custom dependency management system or something like an Eclipse .classpath file as master data for dependency management, it is very easy to write a Gradle plugin to use this data in Gradle. 即使您的项目使用自定义依赖关系管理系统或类似Eclipse .classpath文件作为依赖关系管理的主数据,也可以非常轻松地编写Gradle插件以在Gradle中使用此数据。

I've been maintaining a Custom Ivy resolver for ATG projects (forked from this project ), but Gradle recently deprecated this with version 1.8, and I need to port the implementation to a native Gradle plugin. 我一直在为ATG项目维护一个Custom Ivy解析器 (从这个项目分叉),但Gradle最近不赞成使用1.8版本,我需要将实现移植到本机Gradle插件。

Implementations of ATG use 'modules' (not unlike Gradle projects), that have a MANIFEST.MF file for a module descriptor. ATG的实现使用“模块”(与Gradle项目不同),它具有用于模块描述符的MANIFEST.MF文件。 These files define other 'modules' that a module depends on, and also a list of paths (jars or directories) that form the (direct) classpath for the current module. 这些文件定义了模块所依赖的其他“模块”,以及形成当前模块的(直接)类路径的路径(jar或目录)列表。

eg 例如

ATG-Class-Path: lib/classes.jar lib/commons-beanutils-1.7.jar
ATG-Required: MyProj.core MyProj.integration.webservices DAF.Endeca.Assembler

Module dependencies are transitive, and may refer to custom modules or modules that sit within the ATG product installation. 模块依赖性是可传递的,可以指代ATG产品安装中的自定义模块或模块。 Hence, I need to define a custom repository that can use the ATG product installation as a source of artifacts. 因此,我需要定义一个可以使用ATG产品安装作为工件源的自定义存储库。

Without Gradle, I need to maintain dependencies in the form of 没有Gradle,我需要以形式维护依赖关系

  1. ATG's MANIFEST.MF files ATG的MANIFEST.MF文件
  2. Eclipse .classpath files Eclipse .classpath文件
  3. Dependencies for the Ant build-script Ant构建脚本的依赖关系
  4. SonarQube configurations SonarQube配置

Since I can't get rid of the ATG MANIFEST.MF files, I would like to write a write a custom plugin to allows them to be used in Gradle builds. 由于我无法摆脱ATG MANIFEST.MF文件,我想编写一个自定义插件来允许它们在Gradle构建中使用。 I can then use Gradle as my build system, which can also generate Eclipse .classpath and .project files, and run Sonar against the project. 然后我可以使用Gradle作为我的构建系统,它也可以生成Eclipse .classpath和.project文件,并针对项目运行Sonar。

Gradle seems to have a lot of source code, and rummaging through it for the last couple of days hasn't got me anywhere. Gradle似乎有很多源代码,过去几天翻找它并没有把我带到任何地方。

If someone can point me to a list of interfaces that need to be implemented to (1) implement a custom repository, and (2) implement a custom dependency resolver (to use custom files as module descriptors), that should be enough to get me started. 如果有人可以指出我需要实现的接口列表(1)实现自定义存储库,(2)实现自定义依赖项解析器(使用自定义文件作为模块描述符),这应该足以让我开始。

The Eclipse .classpath use case mentioned above can be solved by parsing that file and translating it to Gradle file dependencies. 上面提到的Eclipse .classpath用例可以通过解析该文件并将其转换为Gradle文件依赖项来解决。 It isn't currently possible to plug in a custom repository implementation. 目前无法插入自定义存储库实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM