Search code examples
gradledependencieslocking

Gradle is not taking the dependency lock file into account


I'm not sure what I'm doing wrong with the gradle dependency lock but when building it with

gradlew clean build

or executing gradlew test gradle is not taking the compileClasspath.lockfile which is stored under {projectroot}/gradle/dependency-locks into account.

I'm using gradlew dependencies --write-locks to write the locks. Using gradle version 6.7.1 and tested with 6.8 as well.

My build.gradle file:

buildscript {
    repositories {
        // ...
    }
    dependencies {
        classpath 'com.commercehub.gradle.plugin:gradle-avro-plugin:0.21.+'
        classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.+'
    }
}

plugins {
    id 'java'
    id 'pl.allegro.tech.build.axion-release' version '1.12.1'
}

group 'xxx'
sourceCompatibility = '11'
targetCompatibility = '11'

configurations {
    compileClasspath {
        resolutionStrategy.activateDependencyLocking()
    }
    intTestImplementation.extendsFrom implementation
}

repositories {
    // ...
}

apply from: "${rootDir}/gradle/versioning.gradle"
project.version = scmVersion.version
apply plugin: 'com.commercehub.gradle.plugin.avro'
apply plugin: 'com.github.johnrengelman.shadow'

dependencies {
    implementation 'org.apache.avro:avro:1.10.+'
    implementation 'org.slf4j:slf4j-log4j12:1.7.+'
    implementation 'org.apache.kafka:kafka-streams:2.6.+'
    implementation 'io.confluent:kafka-streams-avro-serde:6.0.+'
    implementation 'com.fasterxml.jackson.core:jackson-core:2.11.+'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.+'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.+'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.+'
    testImplementation 'org.apache.kafka:kafka-streams-test-utils:2.6.+'
    testImplementation 'com.fasterxml.jackson.core:jackson-core:2.11.+'
    testImplementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.+'
    testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.11.+'
    testImplementation 'junit:junit:4.13.+'
}

test {
    testLogging {
        outputs.upToDateWhen { false }
        showStandardStreams = true
        exceptionFormat = 'full'
    }
}

task run(type: JavaExec) {
    main = 'Class'
    classpath = sourceSets.main.runtimeClasspath
    args = ['configuration/dev.properties']
}

jar {
    manifest {
        attributes(
                'Class-Path': configurations.compileClasspath.collect { it.getName() }.join(' '),
                'Main-Class': 'Class'
        )
    }
}

project.tasks.assemble.dependsOn project.tasks.shadowJar

shadowJar {
    archiveBaseName = "app-standalone"
    archiveClassifier = ''
}

I only realized that the locking is now working due to a bug in a dependency. Lock version is 2.6.0 but gradle is taking 2.6.1 which contains the bug. Due due this the tests are failing

Unfortunately, I couldn't find anything in the gradle docs which pointed me to the issue. Thanks you very much for your help!


Solution

  • My bad. I was not locking the test classpath.

    It works with the following change:

    configurations {
        intTestImplementation.extendsFrom implementation
    }
    
    dependencyLocking {
        lockAllConfigurations()
    }
    

    If there is a better way I'm still interested ;)