dependency-analysis-gradle-plugin icon indicating copy to clipboard operation
dependency-analysis-gradle-plugin copied to clipboard

compileOnly: report unused compileOnly dependencies as 'should be removed'

Open jjohannes opened this issue 3 years ago • 1 comments
trafficstars

Is your feature request related to a problem? Please describe.

If we define dependencies like this but do not use them at all they are not reported.

    compileOnly("androidx.annotation:annotation")
    compileOnly("org.json:json")

The plugin currently discards all advices for dependencies declared as compileOnly. I think this is the right behavior if it is about cases where the dependencies could be implementation or api. Because the plugin cannot know, if a dependency is (not) needed at runtime.

However, the plugin would know if the dependency is not needed at compile time. In this case, the dependency can be safely removed altogether and I think the plugin should give that advice.

Describe the solution you'd like

The plugin should list compileOnly dependencies that are unused in the Unused dependencies which should be removed part of the report.

Describe alternatives you've considered

...

Additional context

A related topic I just thought of (but this is really a very rare case I assume) :

  • compileOnly dependencies which are detected as api should be recommended as compileOnlyApi
  • compileOnlyApi dependencies which are detected as implementation should be recommended as compileOnly

jjohannes avatar Apr 22 '22 06:04 jjohannes

I agree with your general idea. Do you want to work on this changed behavior for compileOnly dependencies?

Secondly, I do want to eventually support compileOnlyApi, but care must be taken because only the core Gradle plugins support this currently. At least, I don't think that Kotlin nor AGP support it.

Edit: to clarify, I think this should be approached in two steps:

  1. Update the logic to not discard advice relating to dependencies declared as compileOnly. If such dependencies are determined to not be necessary for compilation, the plugin should indicate they can be safely removed. If the dependency in question could be api or implementation, continue to not make any recommendation.
  2. Later on, separately, we can consider support for compileOnlyApi.

autonomousapps avatar Apr 22 '22 18:04 autonomousapps