如何在gradle buildscript中强制使用特定的依赖项版本

时间:2017-09-22 13:45:03

标签: gradle dependency-management

gradle-docker-plugin和SpringBootVersion 2.0.0.M4有issue个 M4使用较新的泽西客户端,并使用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 version = 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 = ['...']
}

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

1 个答案:

答案 0 :(得分:0)

您必须在build.gradle依赖项中添加以下内容:This Link

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

之后你必须分开&#34; buildImage&#34;和&#34; tagImage&#34; This link

中建议的任务

我测试了这个:spring boot 2.0.0.M6