autonomousapps/dependency-analysis-gradle-plugin

compileOnly: allow users to define a list of compileOnly(Api) dependencies

開放

#1,387 建立於 2025年2月28日

 (3 則留言) (1 個反應) (1 位負責人)Kotlin (154 個分叉)auto 404
enhancementhelp wantedsponsorable

倉庫指標

星標
 (2,172 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

Often projects use annotation libraries that are only required at compile time. For example: com.github.spotbugs:spotbugs-annotations

If these are placed in the compileOnly or compileOnlyApi scope, the plugin does not complain. It essential treats these as accepted alternatives to implementation or api.

However, if the dependency is missing, the plugin gives an advice like this:

These transitive dependencies should be declared directly:
  implementation("com.github.spotbugs:spotbugs-annotations:4.9.1")

In a large project, users may easily just copy/paste the advice, although in other places of the multi-project compileOnlyApi is used for the dependency.

Describe the solution you'd like

It is difficult or impossible for the plugin to tell if a dependency is still needed at runtime or not. Hence the current behavior. However, the plugin could offer a configuration option to define a list of "compile only libraries" centrally. Then, the information can be picked up when creating the advice. Something like:

dependencyAnalysis {
  structure {
    compileOnly("com.github.spotbugs:spotbugs-annotations")
  }
}

Whether it will be compileOnly or compileOnlyApi should be decided automatically:

  • If it's implementation -> compileOnly
  • If it's api -> compileOnlyApi

This is related to #1210, although the current behavior I see is the opposite to what that issue describes: I get the recommendation for implementation (see example above) although I annotated public API. Need to check.

Describe alternatives you've considered

Using the plugin in combination with https://github.com/gradlex-org/java-module-dependencies, which offers it's own post-processing task, I could offer such a solution in the extension of that plugin. But I would prefer to offer this to all users of DAGP.

貢獻者指南