This project is a shared Android dependency catalog for Automattic projects which uses Gradle's version catalog feature. It's also used for generating a dependency cache that we use in our CIs to speed up our builds.
Add the following to your settings.gradle
:
dependencyResolutionManagement {
versionCatalogs {
sharedLibs {
from("com.automattic:dependency-catalog:$catalogVersion")
// You can override the declared versions with the following syntax:
// version("kotlin", "1.6.21")
}
}
}
Now you can use the catalog in your build.gradle
file as such:
plugins {
alias(sharedLibs.plugins.android.library)
alias(sharedLibs.plugins.kotlin.android)
}
dependencies {
implementation sharedLibs.androidx.recyclerview
}
See Gradle documentation for more details.
trunk
[versions]
section in libs.versions.toml - you can skip this step if you'll reuse an existing version[libraries]
or [plugins]
section:androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "androidx-recyclerview" }
version.ref
refers to the version name from [versions]
section in the libs.versions.toml fileplugins
section in example/build.gradle.kts - make sure to add .apply(false)
. This step is necessary because we use the example
module to generate a dependency cache we use to speed up CI in other projects. We are able to automatically add the library dependencies, so this step is not necessary, but plugins need to be added manually.Could not find {dependency}
error, make sure the repository for the new dependency you've added is included in example/settings.gradle.kts
{prNumber}-{commitSHA1}
. You can use this version to test your project. An easier way to test the version change is to temporarily override it in your project following these instructions.trunk
MINOR
version in MAJOR.MINOR.PATCH
format: git checkout trunk && git pull && git tag {VERSION} && git push origin {VERSION}
We'll need to iterate on our naming conventions, but here are some general guidelines we have used so far:
dagger
, eventbus
, kotlin
, volley
, wellsql
, wiremock
,restAssured
, robolectric
{domainName}-{artifactName}
. Examples: androidx-appcompat
, androidx-room-ktx
, facebook-flipper
, facebook-flipper-network-plugin
, squareup-javapoet
, tinder-statemachine
-
character acts as a form of encapsulation. For example adding androidx-annotation
& androidx-appcompat
will create an androidx
property which will have androidx.annotation
and androidx.appcompat
properties added to it. Keep this structure in mind while using -
character.-
with camelCase if it makes more sense to keep something as one word. For example, com.automattic.android.publish-to-s3
is added as automattic-publishToS3
../gradlew :catalog:generateCatalogAsToml
command. The generated catalog will be available at: catalog/build/version-catalog/libs.versions.toml
./gradlew :example:build
which will use the root libs.versions.toml
file as its version catalog../gradlew :example:build -PcatalogVersion={catalogVersion}
command.Note that example
project does NOT use the generated version catalog from the catalog
project. Although this is not likely to cause a difference in practice, it's an important distinction to be aware of.
We use the example
project to generate a dependency cache which is uploaded to S3 by CI and then used in several projects.
Note that all libraries within the version catalog will be automatically added as a dependency to the example
project, but the plugins need to be added manually.
This feature is not available yet.
We can use renovate to keep the versions in our catalog up to date. We intentionally haven't enabled this feature, as we are not yet in a position to take advantage of it in our projects.
A version catalog is just another Maven publication, so bots such as Dependabot
or renovate
can be used to automatically update the catalog version in projects. However, it's not yet added to any project as we'd like to figure out implementation details and collect feedback before adding this automation.