Skip to content

Commit

Permalink
Fix Gradle version locking (#7239)
Browse files Browse the repository at this point in the history
* feat(build): Implement dependency locking using gradle convention plugin
* feat(ci): Update version locks on nightly builds
  • Loading branch information
PerfectSlayer committed Jul 4, 2024
1 parent b792b2d commit 86a24ac
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.continue.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ jobs:
- run:
name: Build Project
command: >-
{% if is_nightly %}
./gradlew resolveAndLockAll --write-locks
{% endif %}
MAVEN_OPTS="-Xms64M -Xmx256M"
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx2560M -Xms2560M -XX:ErrorFile=/tmp/hs_err_pid%p.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp'"
./gradlew clean
Expand Down
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 86a24ac

Please sign in to comment.