-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Identify and remove unused dependencies #375
Comments
Taking a look at this. I found this tool via web search: https://github.com/autonomousapps/dependency-analysis-gradle-plugin Its a plugin that, once added to id("com.autonomousapps.dependency-analysis") version "<<latest_version>>" Hank |
Looks like 2.7.0. Trying that. I'll report back if/when I get results. Hank |
Well, I knew I only had a few minutes, and now my time is up. Turns out that this is the line I needed to added to id 'com.autonomousapps.build-health' version '2.7.0' // Check for the latest version With that, I ran
I assume this is some sort of incompatibility between the gradle version we're using and the plugin, but I have a meeting with Jim followed by Arvin, so this will probably have to wait until tomorrow. Hank |
Back to this... When building, my gradle version appears to be 7.6.4:
Let me see if the Hank |
The wiki, points me here: That has this code: protected static final GRADLE_7_5 = GradleVersion.version('7.5.1')
protected static final GRADLE_7_6 = GradleVersion.version('7.6.2')
protected static final GRADLE_8_0 = GradleVersion.version('8.0.2')
protected static final GRADLE_8_4 = GradleVersion.version('8.4')
protected static final GRADLE_8_9 = GradleVersion.version('8.9')
protected static final GRADLE_8_10 = GradleVersion.version('8.10.2')
protected static final GRADLE_8_11 = GradleVersion.version('8.11.1')
protected static final GRADLE_LATEST = GRADLE_8_11
// For faster CI times, we only test min + max. Testing all would be preferable, but we don't have till the heat death
// of the universe.
protected static final SUPPORTED_GRADLE_VERSIONS = [
GradleVersions.minGradleVersion,
GRADLE_LATEST,
//GRADLE_8_11,
] The earliest listed version is 7.5.1, which is after 7.4.2. I need to reeducate myself on how to increase our Gradle version, and whether that requires ITSG intervention. I'll also check to see if we can get our hands on a version of the tool that lists 7.4 in the compatible versions. Hank |
There is a Kotlin file in the repo that indicates the minimum version may be 7.4: /** Minimum supported version of Gradle. */
@JvmField val minGradleVersion: GradleVersion = gradle74 Hmmm... Hank |
I edited the previous comment. I pasted the wrong info from the clipboard. Hank |
To be clear, our build is using 7.6.4. We should upgrade to 8 before too long, but it generally involves a non-trivial amount of work. The version of gradle is set in |
|
Thanks, James. Not sure why I thought we were using 7.4.2. We're using 7.6.4. That should be compatible, and yet it seems that the tool is incorrectly casting a variable internal to Gradle: Hank |
That class, If I update the
I think this goes back to James's comment about upgrading gradle involving a, "non-trivial amount of work". Let me first check if there are other tools available to do what we want to do. If not, I'll tackle the Gradle version update, first, and then revisit this ticket. I had proposed tackling updating dependency versions as my next big task (starting with #68 before the holidays), and this ties well into that. Thanks, Hank |
This may be an option: https://www.baeldung.com/gradle-finding-unused-dependencies It uses Hank |
So I was able to get it to run, but it was consistently not reporting any issues. However, the lack of task output was disconcerting:
So I found a command to generate reports in https://www.baeldung.com/java-gradle-lint-intro:
Upon running that an capturing screen output, I get a bunch of output like this:
So either we have no lint violations, including no unused dependencies, or its just not checking/reporting them. Let me see if there is some sort of option I have to set in order to turn on the lint violations checking. Hank |
From what I can tell, I don't think we have any unused dependencies. The One thing I want to do before closing this is insert an unused dependency artificially to see if Hank |
I artificially added this to
Hank |
So Taking a step back, tomorrow I plan to check and see if the tools we've been using already recognized unused dependencies. To be honest, when updating dependencies and using the tools that we have to support it, which I used just a few weeks ago, I didn't really check to see if they noted unused dependencies somehow. I'll check that out tomorrow. I have other work to do for the rest of today. Thanks, Hank |
I think the tools we use for deployment are focused on "positive" inspection, i.e., listing dependencies, checking for updates, checking their CVEs etc. This is more like a "negative" task, i.e., list unused dependencies or dependencies that should be explicit and are instead transitive. I don't recall using tooling to check for unused dependencies, but I did often scan the |
I mean, you could probably use the built-in tasks (e.g. |
Did you add any rules? The linked article seems to suggest these should be made explicit, such as:
|
Yes. The rule was,
I would think that would capture Hank |
It made no difference using 'unused-dependency'. I'm almost certainly doing something wrong, given that I added guava to
Brute force is an option for this if all else fails, so I might do just that, James. Or, as I mentioned above, I may tackle the Gradle 8 upgrade, first, since that has to happen eventually, and then tackle the unused dependencies later. Thanks, Hank |
Did you add it with global scope, i.e., to capture all sub-projects? |
It is probably something simple. More than likely, the tool isn't broken or unusable. Our |
Returning to this...
Yes. I applied the plugin and declared the rule in the Agree on it probably being something simple. Just have to figure out what, Hank |
This is probably a stupid question, but look at the source... Are we using groovy or kotlin in our build.gradle? Hank |
Groovy, the default :) Yeah, it won't work with Kotlin, I spotted that too. |
Thanks, James. Just noting here that I'm going to try to up the logging somehow to see if I can get detailed information. Looking in the github repo, https://github.com/nebula-plugins/gradle-lint-plugin, its not obvious to me how to do that or if it can be done. First, however, I have about 90 minutes of meetings, Hank |
Looks like log4j, and, if this properties file is correct and used (no idea), it should be debug by default: https://github.com/nebula-plugins/gradle-lint-plugin/blob/main/src/main/resources/log4j.properties Hank |
At this point, it might just be easier to do a manual check. Let me see what would be involved, starting with the command to obtain the dependencies. Hank |
I started with
So I think it is actually a tool that I need, and that means fighting through the problems of the two tools I've found so far, or finding another one. I'm going to put this task on hold and revisit it next week, hopefully. I want to take a look at the Podman stuff Evan has been working on. Hank |
I want to find and use a tool to identify any un-used dependencies and remove them from out project.
This will tangently help with #158 and also help keep a cleaner project overall
The text was updated successfully, but these errors were encountered: