【问题标题】:Gradle is not taking the dependency lock file into accountGradle 没有考虑依赖锁文件
【发布时间】:2021-01-18 08:32:21
【问题描述】:

我不确定我在使用 gradle 依赖锁时做错了什么,但是在构建它时

gradlew clean build

或执行 gradlew test gradle 没有采用存储在下面的 compileClasspath.lockfile {projectroot}/gradle/dependency-locks 考虑到。

我正在使用 gradlew dependencies --write-locks 来写锁。使用 gradle 版本 6.7.1 并使用 6.8 进行了测试。

我的 build.gradle 文件:

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 = ''
}

由于依赖项中的错误,我才意识到锁定现在正在工作。锁定版本是 2.6.0,但 gradle 正在使用包含错误的 2.6.1。由于这个原因,测试失败了

不幸的是,我在 gradle 文档中找不到任何指向该问题的内容。 非常感谢您的帮助!

【问题讨论】:

    标签: gradle dependencies locking


    【解决方案1】:

    我的错。我没有锁定测试类路径。

    它适用于以下更改:

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

    如果有更好的方法我仍然感兴趣;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多