autonomousapps / dependency-analysis-gradle-plugin

Gradle plugin for JVM projects written in Java, Kotlin, Groovy, or Scala; and Android projects written in Java or Kotlin. Provides advice for managing dependencies and other applied plugins
Apache License 2.0
1.79k stars 117 forks source link

Warning on java-library and spring-boot appears for all project tasks #1270

Open pkubowicz opened 2 weeks ago

pkubowicz commented 2 weeks ago

Build scan link https://scans.gradle.com/s/7iev7o7xnp5m4/console-log

Plugin version 2.1.0

Gradle version 8.10.1

JDK version 17.0.12

(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version N/A

(Optional) Android Gradle Plugin (AGP) version N/A

(Optional) reason output for bugs relating to incorrect advice N/A

Describe the bug

  1. I see warnings from dependency-analysis plugin although I don't execute it.
  2. Plugins should refrain from doing unneeded things in configuration phase. This is inefficient from build performance point of view, as well as distracting (stealing attention when not used) from user experience point of view.
  3. The warning appears twice, although I have just 1 project.

To Reproduce Steps to reproduce the behavior:

  1. Run gradle classes in
plugins {
    id("com.autonomousapps.dependency-analysis") version "2.1.0"
    id("org.springframework.boot") version "3.3.1"
    `java-library`
}

repositories {
    mavenCentral()
}

Console output:

Calculating task graph as no cached configuration is available for tasks: classes

> Configure project :
(dependency analysis) You have both java-library and org.springframework.boot applied. You probably want java, not java-library.
(dependency analysis) You have both java-library and org.springframework.boot applied. You probably want java, not java-library.

BUILD SUCCESSFUL in 7s

Expected behavior The warning may be fine, but only during execution phase, this is: only when buildHealth task is in the execution graph.

When the task is not in the execution graph, I shouldn't see any messages from this plugin.

Additional context This bug is old, was present in 1.33.0 and some older versions.

One more question: what is the reason for warning about those plugins used together? What am I losing by continuing doing what I am warned about?

autonomousapps commented 5 days ago

Here's the code in question:

// Regardless of the fact that this is a "java-library" project, the presence of Spring
// Boot indicates an app project.
val dependencyAnalyzer = if (pluginManager.hasPlugin(SPRING_BOOT_PLUGIN)) {
  logger.warn(
    "(dependency analysis) You have both java-library and org.springframework.boot applied. You probably " +
      "want java, not java-library."
  )

So this is really just about reducing confusion. It also does this per source set, which is why you're seeing the warning twice. (Presumably once for main and once per test source set.)

This could be optimized.

pkubowicz commented 5 days ago

Back to the question I asked at the end. Is the warning valid? Is anything bad happening in practice if you apply both plugins?

I'm asking because maybe the simplest fix is to remove the code above altogether, instead of trying to improve it.

autonomousapps commented 4 days ago

The java-library plugin will add api configurations for all source sets, even though these are unnecessary and not used for application modules (which is what I think a "spring boot" module is, right?). So it makes your build less efficient, although in a fairly small way.

autonomousapps commented 15 hours ago

To bring it back to the warning, I think you can switch your plugin from java-library to java and your build should still Just Work. If that's not the case, please let me know.

pkubowicz commented 14 hours ago

I'm applying java-library with a convention plugin. Actually, I have the convention plugin 'kotlin' that includes the convention plugin 'jvm' that applies 'java-library'.

So to satisfy the irritating warning from the plugin, I would need to copy-paste non-trivial logic of 'jvm' convention to 'jvm-non-library' convention, then copy-paste 'kotlin' to 'kotlin-non-library'. Or add another level of 'inheritance'.

I don't see any justification of such a damage to my source code.

The consequence of my unnecessary use of java-library is that 2 subprojects out of 80 have an unused configuration declared. I don't expect this having any footprint other than statistical noise.

The warning from dependency-analysis 2.x is so noisy that I decided not to update from 1.x. It makes no sense that several teams see unnecessary warnings multiple times per day, from a plugin that is not used at all for daily work.