-
-
Notifications
You must be signed in to change notification settings - Fork 132
Customizing plugin behavior
The plugin provides a dependencyAnalysis {}
extension (com.autonomousapps.DependencyAnalysisExtension
)
for configuration.
By default, the plugin’s tasks will not fail a build upon detection of dependency issues; they simply print results to console and to disk. If you would prefer your build to fail if there are issues, you can configure the plugin as follows:
dependencyAnalysis
issues {
// configure for all projects
all {
// set behavior for all issue typesk
onAny {
severity(<'fail'|'warn'|'ignore'>) // default is 'warn'
exclude('an:external-dep', 'another:external-dep', ':a:project-dep')
}
// or configure per-type
onUnusedDependencies { ... }
onUsedTransitiveDependencies { ... }
onIncorrectConfiguration { ... }
onUnusedAnnotationProcessors { ... }
onRedundantPlugins { ... } // no excludes in this case
}
// or configure per project
project(':lib') {
...
}
}
}
Or if you prefer, you can configure this in the subproject’s build script directly (instead of using project(':some-project') {}
dependencyAnalysis {
onAny {
severity(<'fail'|'warn'|'ignore'>)
exclude('an:external-dep', 'another:external-dep', ':a:project-dep')
}
onUnusedDependencies { ... }
onUsedTransitiveDependencies { ... }
onIncorrectConfiguration { ... }
onUnusedAnnotationProcessors { ... }
onRedundantPlugins { ... } // no excludes in this case
}
If your build fails, the plugin will print the reason why to console, along with the path to the report. Please see [Use cases](#use-cases), above, for help on understanding the report.
Since v0.41.0
A facade dependency is a family of dependencies that are meant to be consumed via a facade. For example, the org.jetbrains.kotlin:kotlin-stdlib-jdk8
dependencies transitively includes org.jetbrains.kotlin:kotlin-stdlib
, making this pair of dependencies into a family. Users are typically expected to declare the facade (in this case the -jdk8
variant), and use the transitively included dependency (the un-decorated "core" variant) without having to declare it.
By default, the plugin will consider kotlin-stdlib-
family of dependencies to be in such a family, and will not warn users about using the core kotlin-stdlib
artifact without declaring it; nor will it warn about the kotlin-stdlib-
variant being "unused" if a member of the family is used. This behavior is configurable.
If you want to add custom "facade" groups (by "group" we mean org.jetbrains.kotlin
to continue the example), you can do the following:
dependencyAnalysis {
setFacadeGroups("com.some-group", "com.another-group") // varargs; or
setFacadeGroups(["com.some-group", "com.another-group"]) // iterable
}
Please note that, when explicitly setting the facade groups, this will unset the default Kotlin group. If you also want that, you must add it yourself.
If this facade behavior is considered undesirable, you may set an empty group as follows:
dependencyAnalysis {
setFacadeGroups()
}
In Android, it is common to add dependencies like androidx.core:core-ktx
and
androidx.preference:preference-ktx
. It is also apparently quite common for apps to not use the
Kotlin extensions provided by these dependencies, but only the transitive dependencies included with
these so-called "ktx" dependencies. When this (quite often) happens, the plugin will — correctly — report that the ktx dependency is unused, and some of its transitive dependencies are used, and the
dependency graph should be updated accordingly. Android developers resist this advice, and since
this resistance is fortified by the vast and growing ecosystem of these dependencies, along with
documentation that uniformly recommends including them in apps, this plugin now provides a
configuration option to "ignore ktx dependencies". That may be enabled as follows:
dependencyAnalysis {
issues {
all {
ignoreKtx(true) // default is false
}
}
}
This will only ignore ktx dependencies if one of their transitives is actually used. If your app using neither of the direct nor any of its transitives, the plugin will still suggest removing that ktx dependency.
On very large projects, the plugin’s default behavior of auto-applying itself to all subprojects can have major performance impacts. To mitigate this, the plugin can be configured so that it must be manually applied to each subproject of interest.
dependencyAnalysis {
autoApply(false) // default is true
}
On larger builds, the plugin’s default behavior of printing the advice directly to the console can have negative performance ramifications (printing is slow). If you are comfortable reading the advice as json (printed to disk), you can reduce the "chattiness" like so:
dependencyAnalysis {
chatty(false) // default is true
}
See the dedicated page.