简体   繁体   English

查找未使用的Gradle运行时依赖项

[英]Find unused gradle runtime dependencies

I am in the process of updating a large set of legacy java applications. 我正在更新大量旧版Java应用程序。 The current builds use ant with its dependencies coming from each project's lib directory. 当前版本使用ant及其依赖项来自每个项目的lib目录。 The dependencies are part of each project and checked in to source control. 依赖关系是每个项目的一部分,并签入到源代码管理中。 The purpose of the updates is to convert the builds to gradle and use a maven repository for dependency management. 更新的目的是将构建转换为gradle,并使用maven存储库进行依赖项管理。 For simplicity, the legacy builds copied dependencies from other project's lib directories using an ant construct like: 为简单起见,旧版使用类似ant的构造从其他项目的lib目录构建复制的依赖项:

<fileset dir="../anotherlegacyproject/lib">
    <include name="**/*.jar" />
</fileset>

This approach is used for both compile and runtime dependencies. 此方法用于编译和运行时依赖项。 While this works, it leads to bloat of the deployment artifacts because of the many jars included which are not necessary at runtime. 尽管这行得通,但由于其中包含许多jar,而在运行时不需要,因此导致部署工件膨胀。 For example, many of the projects include junit, hamcrest, and jaxb-xjc in the runtime even though they are only used for compile or test . 例如,许多项目在运行时中都包含junit,hamcrest和jaxb-xjc,即使它们仅用于编译测试 Most of the projects create both a zip file and an RPM containing deployable applications. 大多数项目都会创建一个zip文件和一个包含可部署应用程序的RPM。 I would like to only include the required runtime dependencies in the RPMs. 我想只有在包含了RPMs所需的运行依赖。

I am trying to determine a reliable method for identifying these unused runtime dependencies. 我正在尝试确定一种可靠的方法来识别这些未使用的运行时依赖项。

I have reviewed the post: How to find\\remove unused dependencies in gradle but this does not address unused runtime dependencies. 我已经查看了以下文章: 如何在gradle中查找/删除未使用的依赖项,但这不能解决未使用的运行时依赖项。 I have tried using the following gradle plugins, none of which identify unused runtime dependencies: 我尝试使用以下gradle插件,但其中没有一个可以标识未使用的运行时依赖项:

  • github.com/nebula-plugins/gradle-lint-plugin github.com/nebula-plugins/gradle-lint-plugin
  • github.com/wfhartford/gradle-dependency-analyze github.com/wfhartford/gradle-dependency-analyze
  • docs.gradle.org/current/userguide/jdepend_plugin.html docs.gradle.org/current/userguide/jdepend_plugin.html

I am open to any solution that will reliably work, but my preferences would be in this order: 我对任何可以可靠工作的解决方案都持开放态度,但我的偏好按以下顺序排列:

  1. An existing gradle plugin 现有的gradle插件
  2. Code that could be incorporated into the build.gradle file or groovy code packaged as a plugin 可以合并到build.gradle文件中的代码或打包为插件的groovy代码
  3. Anything else 还要别的吗

Recently we migrated some project from 1.6 to 1.8, needed to find out unused jar. 最近,我们将一些项目从1.6迁移到1.8,这需要找出未使用的jar。 I was trying to use some plugin and tool but could not solve my issue. 我试图使用一些插件和工具,但无法解决我的问题。 Over stack overflow I got some insight to fix this issue. 在堆栈溢出中,我获得了一些见解来解决此问题。 Below are the steps to find out unused jar in project. 以下是找出项目中未使用的jar的步骤。

  1. First you need to take latest EAR/WAR of your module. 首先,您需要获取模块的最新EAR / WAR。 Suppose you module name is CheckDependency, so take latest EAR/WAR and get it out lib folder. 假设您的模块名称为CheckDependency,所以使用最新的EAR / WAR并将其从lib文件夹中取出。
  2. Now in eclipse replace lib folder of your module with new one, which taken from EAR/WAR. 现在在eclipse中,用EAR / WAR中的新文件夹替换模块的lib文件夹。
  3. Eclipse go to your module and select Gradle(STS)[This should be installed in your machine]-->Hit Task Quick Launcher -->Select projectTattleTaleReport It will generate all report in you target folder with name tattleReport Eclipse转到您的模块,然后选择Gradle(STS)[这应该安装在您的计算机中]->命中任务快速启动器 ->选择projectTattleTaleReport它将在目标文件夹中生成所有名为tattleReport的报告

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

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