autonomousapps/dependency-analysis-gradle-plugin

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

オープン

#1,387 opened on 2025/02/28

 (3 件のコメント) (1 件のリアクション) (1 人の担当者)Kotlin (154 件のフォーク)auto 404
enhancementhelp wantedsponsorable

Repository metrics

Stars
 (2,172 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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.

コントリビューターガイド