Skip to content

Commit

Permalink
feat(build): Implement dependency locking using gradle convention plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
PerfectSlayer committed Jun 25, 2024
1 parent 2d36ca7 commit 114d414
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
28 changes: 2 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ buildscript {
}

plugins {
id "datadog.dependency-locking"

id "com.diffplug.spotless" version "6.13.0"
id 'com.github.spotbugs' version '5.0.14'
id "de.thetaphi.forbiddenapis" version "3.5.1"
Expand Down Expand Up @@ -192,32 +194,6 @@ def testAggregate(String baseTaskName, includePrefixes, excludePrefixes, boolean
createRootTask "${baseTaskName}Check", 'check'
}

// To lock dependency versions, run `./gradlew resolveAndLockAll --write-locks`
tasks.register('resolveAndLockAll') {
notCompatibleWithConfigurationCache("Filters configurations at execution time")
doFirst {
assert gradle.startParameter.writeDependencyLocks
}
doLast {
allprojects { project ->
project.configurations.findAll {
it.canBeResolved && !it.name.startsWith('incrementalScalaAnalysis')
}.each { it.resolve() }
}
}
}

allprojects { project ->
project.dependencyLocking {
lockAllConfigurations()
//lockmode set to LENIENT because there are resolution
//errors in the build with an apiguardian dependency.
//See: https://docs.gradle.org/current/userguide/dependency_locking.html for more info
lockMode = LockMode.LENIENT

}
}

testAggregate("smoke", [":dd-smoke-tests"], [])
testAggregate("instrumentation", [":dd-java-agent:instrumentation"], [])
testAggregate("profiling", [":dd-java-agent:agent-profiling"], [])
Expand Down
32 changes: 32 additions & 0 deletions buildSrc/src/main/kotlin/datadog.dependency-locking.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This plugin enables dependency locking.
*
* The goal is to be able to later rebuild any version, by pinning floating versions.
* It will also help IDEs not having to re-index any latest library release.
* Pinned versions will be updated by the CI on a weekly basis.
*
* Pinned version can be updated using: ./gradlew resolveAndLockAll --write-locks
*
* See https://docs.gradle.org/current/userguide/dependency_locking.html
*/

project.dependencyLocking {
lockAllConfigurations()
//lockmode set to LENIENT because there are resolution
//errors in the build with an apiguardian dependency.
//See: https://docs.gradle.org/current/userguide/dependency_locking.html for more info
lockMode = LockMode.LENIENT
}

tasks.register("resolveAndLockAll") {
notCompatibleWithConfigurationCache("Filters configurations at execution time")
doFirst {
require(gradle.startParameter.isWriteDependencyLocks)
}
doLast {
configurations.filter {
// Add any custom filtering on the configurations to be resolved
it.isCanBeResolved
}.forEach { it.resolve() }
}
}
2 changes: 2 additions & 0 deletions gradle/java.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
apply plugin: 'datadog.dependency-locking'

apply from: "$rootDir/gradle/java_deps.gradle"
apply from: "$rootDir/gradle/java_no_deps.gradle"

0 comments on commit 114d414

Please sign in to comment.