如何在gradle构建脚本中强制使用特定的依赖关系版本

eh57zj3b  于 2022-12-23  发布在  其他
关注(0)|答案(2)|浏览(194)

有一个issue用于gradle-docker插件和SpringBootVersion 2.0.0.M4
M4使用较新的Jersey客户端,使用docker-plugin会导致异常:

ERROR com.github.dockerjava.core.async.ResultCallbackTemplate - Error during callback
java.lang.IllegalStateException: InjectionManagerFactory not found.
    at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:98)
    at java.util.Optional.orElseThrow(Optional.java:290)
    at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:98)
    at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:68)
    at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:432)
    at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:341)
    at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:826)
    at org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:285)
    at org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:143)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:112)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:108)
    at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:99)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:456)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:357)
    at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
    at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
    at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

我的主项目中的BuildScript:

buildscript {
    ext {
        springBootVersion = "2.0.0.M4"
    }

    repositories {
        maven { url "https://repo.spring.io/plugins-snapshot" }
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
    }
}
....

如您所见,我们加载了spring-boot-gradle-plugin版本=2.0.0.M4及其所有依赖项。
我的子项目build.gradle:

apply plugin: "org.springframework.boot"
apply from: "docker.gradle"
....

最重要的是,docker.gradle文件与子项目的build.gradle位于同一目录中:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.bmuschko:gradle-docker-plugin:3.0.11'
    }
}

apply plugin: com.bmuschko.gradle.docker.DockerRemoteApiPlugin

import com.bmuschko.gradle.docker.tasks.image.*
...
task buildImage(type: DockerBuildImage, dependsOn: copyDockerFiles) {
    version.release = true
    dockerFile = file("${projectDir}/build/docker/Dockerfile")
    inputDir = file("${projectDir}/build/docker")
    tags = ['...']
}

我的问题:如何知道哪个版本的jersey客户端加载SpringBoot 2.0.0.M4?如何强制docker.gradle中的gradle使用特定版本的jersey客户端?添加到类路径不起作用。我认为gradle将只使用最新版本,该版本将由SpringBoot 2.0.0.M4加载

yiytaume

yiytaume1#

您必须按照中的说明在build.gradle依赖项中添加以下内容:此链接

dockerJava 'com.nirima:docker-java-shaded:0.16.2'
dockerJava 'org.slf4j:slf4j-simple:1.7.5'
dockerJava 'cglib:cglib:3.2.0'

之后,您必须按照此链接中的建议将“buildImage”和“tagImage”任务分开
我已经用以下软件进行了测试: Spring Boot 2.0.0.M6

prdp8dxp

prdp8dxp2#

我只是做了:

dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
        classpath "org.mozilla:rhino:1.7.14"
        classpath ( group: 'org.apache.commons', name: 'commons-text'){
           version{
               strictly '1.10.0'
           }
        }
}

相关问题