Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Gradle Version Catalogs if present #794

Open
inktomi opened this issue Sep 28, 2022 · 2 comments · May be fixed by #837
Open

Use Gradle Version Catalogs if present #794

inktomi opened this issue Sep 28, 2022 · 2 comments · May be fixed by #837
Labels
enhancement New feature or request help wanted Extra attention is needed sponsorable You can sponsor me to work on this issue!

Comments

@inktomi
Copy link

inktomi commented Sep 28, 2022

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

In a large project which makes use of version catalogs, it would be ideal if instead of suggestions like "add implementation 'androidx.activity:activity:1.4.0'" the plugin was able to resolve the dependency name from the gradle version catalog and instead report "add implementation libs.androidx.activity".

Describe the solution you'd like

If there is a version catalog present, instead of reporting the raw dependency, look for a match in the catalog's items. There are methods off VersionCatalog which might be useful here.

Describe alternatives you've considered

The alternative would be not doing this, which is reasonable - and perhaps there is not the API support from Gradle itself to do this reverse lookup. It'd be unfortunate though, as this lookup would make the suggestions and automatic fixes much more usable for projects using version catalogs.

@autonomousapps autonomousapps added the enhancement New feature or request label Oct 10, 2022
@autonomousapps
Copy link
Owner

The plugin currently has an API that would let you do this yourself. See here.

Alternatively, PRs are welcome (ideally leveraging the above-mentioned API). I don't have any immediate plans to implement this myself.

@autonomousapps autonomousapps added help wanted Extra attention is needed sponsorable You can sponsor me to work on this issue! labels Oct 10, 2022
@daanschipper
Copy link
Contributor

daanschipper commented Dec 13, 2022

For anyone interested, this is how you can add the dependencies in the version catalog:

dependencyAnalysis {
    dependencies {
        // Adds the defined aliases in the version catalog to be used when printing advice and rewriting build scripts.
        def versionCatalogName = "libs"
        def versionCatalog = project.extensions.getByType(VersionCatalogsExtension).named(versionCatalogName)
        versionCatalog.getLibraryAliases().forEach({ String alias ->
            map.put(versionCatalog.findLibrary(alias).get().get().toString(), "${versionCatalogName}.${alias}")
        })
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed sponsorable You can sponsor me to work on this issue!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants