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.66k stars 116 forks source link

Add wildcard support for exclusion rules #1184

Open rvandermeulen opened 2 months ago

rvandermeulen commented 2 months ago

Is your feature request related to a problem? Please describe. Right now, if I want to ignore multiple packages from the same project, I have to list each one individually. And the rules need to be updated any time a new package from that project gets added. This can be a bit cumbersome.

Describe the solution you'd like Add wildcard support to the exclude rules, so something like exclude('project:*') would work.

Describe alternatives you've considered Excluding each individually.

Additional context N/A

autonomousapps commented 1 month ago

Thanks for the issue.

Can you explain why you have this need to exclude so many things? Is there some issue with the analysis?

jonapoul commented 1 month ago

+1 for me. Personally, I'd like it because I keep module diagrams of my projects to illustrate how modules link together. Unless I can exclude projects from onIncorrectConfiguration, I'm forced to add loads of interleaving direct links between nodes in the diagram, which makes the whole thing more difficult to follow.

Ideally I'd make most of those links api instead of implementation, which IMO is easier to understand.

rvandermeulen commented 1 month ago

Thanks for the issue.

Thanks for the reply and for creating this tool in the first place!

Can you explain why you have this need to exclude so many things? Is there some issue with the analysis?

Certainly. I have two main cases in mind for this:

Hopefully that makes sense. Happy to try to clarify anything if needed.

autonomousapps commented 1 month ago

Unless I can exclude projects from onIncorrectConfiguration

So you're saying you prefer to have incorrectly declared dependencies? I'm not sure I want to make that easier to do.

autonomousapps commented 1 month ago

I suspect that you might find the bundle feature very useful for meeting your needs. It already permits regex.

https://github.com/autonomousapps/dependency-analysis-gradle-plugin/wiki/Customizing-plugin-behavior#logical-dependency-groups-aka-dependency-bundles

rvandermeulen commented 1 month ago

I'm having a bit of difficulty figuring out how to apply bundles to our situation.

I would have expected behavior something along the lines of https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/904 but obviously that's not how they're designed to work. I'm not seeing how to make the connection between defining a bundle and telling the plugin to ignore any transitive dependencies applicable to it.

rvandermeulen commented 1 month ago

@autonomousapps Maybe I'm misunderstanding how bundles are meant to work. Do I need to create a bundle which is chained up to the parent dependency that pulls in the transitive ones I'm trying to ignore?

autonomousapps commented 1 month ago

So I think what you might want is something like this:

// build.gradle
dependencyAnalysis {
  structure {
    bundle("project-group") { // name is arbitrary but must be unique
      primary(":name-of-project-with-api-deps") // the project dep you want to declare
      include(":<regex that matches the projects you don't want to have to declare>")
    }
  }
}
rvandermeulen commented 1 month ago

Thanks, I'll play around with that!

eygraber commented 1 month ago

This would be helpful for something like compose, especially with multiplatform where it redirects to jetpack compose artifacts.

I tried something like #904 but that didn't work either.


dependencyAnalysis {
  structure {
    bundle("androidx-compose") {
      include("^androidx.compose.*$")
    }
  }

  issues {
    all {
      onAny {
        severity("fail")
        exclude("androidx-compose")
      }
    }
  }
}
eygraber commented 1 month ago

Another wildcard that would be useful is for project (e.g. ignoring everything for anything under :samples). I tried bundles for that, but it didn't work either (or I misconfigured it):

dependencyAnalysis {
  structure {
    bundle("samples") {
      primary(":samples")
      include(":samples:.*")
    }
  }

  issues {
    all {
      onAny {
        severity("fail")
      }
    }

    project("samples") {
      onAny {
        severity("ignore")
      }
    }
  }
}