gradle-docker-plugin: gradle and spring boot plugin and errors with docker java

thanks alot for the great plugin. we have sadly encountered a strange issue with the docker java plugin ever since we upgraded to spring boot M4.

Execution failed for task ':mrm-external_ota:buildImage'.
> Could not resolve all dependencies for configuration ':mrm-external_ota:dockerJava'.
   > Could not determine artifacts for javax.ws.rs:javax.ws.rs-api:2.1
      > Could not get resource 'https://[internalrep]/repository/maven-central/javax/ws/rs/javax.ws.rs-api/2.1/javax.ws.rs-api-2.1.$%7Bpackaging.type%7D'.
         > Could not HEAD 'https://[internalrep]/repository/maven-central/javax/ws/rs/javax.ws.rs-api/2.1/javax.ws.rs-api-2.1.$%7Bpackaging.type%7D'. Received status code 500 from server: Server Error

while I have no problem resolving and building the project, it fails while fetching the deps during docker image builds and as I see it $%7Bpackaging.type%7D is not replaced correctly which should be the package type variable.

If I switch back to spring boot M3 plugin, this will run as well, so not sure whats going on!

Any ideas ?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 43

Commits related to this issue

Most upvoted comments

I have similar issues with Springboot 2.0M4

Seems to be related to jersey and a new version with Springboot 2.0M4, not sure why that causes it.

I get this stacktrace with M4 but M3 works fine [dockerjava-jaxrs-async-0] 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)

I was getting the error too. Adding jcenter() fixed it for me. The clue was from Ben Muschko found here:

ATTENTION: as of version 3.2.5 of this plugin we are using the docker-java-shaded library, in favor of docker-java, which itself is hosted on jcenter ONLY.

repositories {
    jcenter()
}
repositories {
    maven { url 'https://oss.sonatype.org/content/groups/public' }
}

dependencies {
    dockerJava 'com.github.docker-java:docker-java:3.1.0-SNAPSHOT'
    dockerJava 'org.slf4j:slf4j-simple:1.7.5'
    dockerJava 'cglib:cglib:3.2.0'
}

https://github.com/takuro-yamane/gradle-docker-plugin-spring-boot-m4

@cdancy thank you! That worked!

@orzeh put together a project solely for the purpose of building a shaded version of docker-java which I will maintain and publish to jcenter. My thinking is to use this, in place of depending on docker-java, which should get us around issues like this once and for all. As the docker-java project itself seems to not want to do the work I went ahead and knocked it out. Give it a look over and let me know what you think of the idea.

https://github.com/project-aries/docker-java-shaded

Bumped into this issue today as well. More will come as Spring Boot is now at RC2. It won’t be long until the masses come 😃

@cdancy I upgraded to latest version 3.2.5, getting below error -

Could not resolve all files for configuration ':dockerJava'.
   > Could not find com.aries:docker-java-shaded:3.0.14.
     Searched in the following locations:
         file:/Users/akshaybansod/.m2/repository/com/aries/docker-java-shaded/3.0.14/docker-java-shaded-3.0.14.pom
         file:/Users/akshaybansod/.m2/repository/com/aries/docker-java-shaded/3.0.14/docker-java-shaded-3.0.14.jar
         https://repo1.maven.org/maven2/com/aries/docker-java-shaded/3.0.14/docker-java-shaded-3.0.14.pom
         https://repo1.maven.org/maven2/com/aries/docker-java-shaded/3.0.14/docker-java-shaded-3.0.14.jar
         http://maven.twttr.com/com/aries/docker-java-shaded/3.0.14/docker-java-shaded-3.0.14.pom
         http://maven.twttr.com/com/aries/docker-java-shaded/3.0.14/docker-java-shaded-3.0.14.jar

build.gradle

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile "com.bmuschko:gradle-docker-plugin:3.2.5"
}

I had previously worked-around the “Could not build image: null” by having separate “buildImage” and “tagImage” tasks as suggested in https://github.com/bmuschko/gradle-docker-plugin/issues/399. Leaving off the tag property in the buildImage seems to be key.

task buildImage(type: DockerBuildImage) {
	dependsOn copyDockerfileForDocker, copyJarForDocker
	inputDir = file('build/dockerAssemble')
}

task tagImageLatest(type: DockerTagImage) {
	dependsOn buildImage
	targetImageId { buildImage.getImageId() }
	repository = "mydockerimage"
	tag = "latest"
}

That, in conjunction with the changes in the linked repository from @orzeh above seems to have allowed me to build and dockerize a Spring Boot 2.0 application (2.0.0.M5 specifically).

@gnilron I would reach out and try to get an updated shaded jar if that’s what works for you. You could always hop on the docker-java gitter channel and bug those guys about providing one OOTB as I’ve done as much many times myself 😃

I’ve just created small Spring Boot M.4 application and was able to build a Docker image without any issues.

@cdancy I already added jcenter() in repositories . Still it fails during buildimage

for me spring-boot RC1 worked with gradle-docker-plugin 3.2.4 with the following in dependencyManagement section:

        dependency 'javax.ws.rs:javax.ws.rs-api:2.1'
        dependency 'com.github.docker-java:docker-java:3.1.0-SNAPSHOT'

@iNikem we will probably wait until SB 2.0 is released. That being said we may not be able to fix it without changes in docker-java.

@rafalQA please check @takuro-yamane example - it seems to work.

@takuro-yamane thanks for sharing this! I checked and it works well with latest M7 too 👍

@wwadge I created repository with example: https://github.com/orzeh/gradle-docker-plugin-spring-boot-m4

It builds image, so issue reported here is fixed, however it seems that this shaded library is out of date, because build fails with:

orzeh@dell:~/gradle-docker-plugin-spring-boot-m4$ gradle buildImage -S
Step 1/2 : FROM alpine
---> 7328f6f8b418
Step 2/2 : RUN ps -a
---> Using cache
---> 9f2f8641b4d4
Successfully built 9f2f8641b4d4
Successfully tagged spring-boot-app:0.0.1-SNAPSHOT

> Task :buildImage
Building image using context 'gradle-docker-plugin-spring-boot-m4'.
Using tag 'spring-boot-app:0.0.1-SNAPSHOT' for image.


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildImage'.
> Could not build image: null

This seems to be this issue in docker-java

There’s already a shaded version of docker-java published. This patch will make it work:

diff --git a/src/main/groovy/com/bmuschko/gradle/docker/DockerRemoteApiPlugin.groovy b/src/main/groovy/com/bmuschko/gradle/docker/DockerRemoteApiPlugin.groovy
index c5431d8..506d89e 100644
--- a/src/main/groovy/com/bmuschko/gradle/docker/DockerRemoteApiPlugin.groovy
+++ b/src/main/groovy/com/bmuschko/gradle/docker/DockerRemoteApiPlugin.groovy
@@ -50,7 +50,7 @@ class DockerRemoteApiPlugin implements Plugin<Project> {
 
         Configuration config = project.configurations[DOCKER_JAVA_CONFIGURATION_NAME]
         config.defaultDependencies { dependencies ->
-            dependencies.add(project.dependencies.create("com.github.docker-java:docker-java:$DockerRemoteApiPlugin.DOCKER_JAVA_DEFAULT_VERSION"))
+            dependencies.add(project.dependencies.create("com.nirima:gradle-docker-plugin:0.16.2"))
             dependencies.add(project.dependencies.create('org.slf4j:slf4j-simple:1.7.5'))
             dependencies.add(project.dependencies.create('cglib:cglib:3.2.0'))
         }
 

From here: https://github.com/jenkinsci/docker-plugin/blob/master/docker-java-shaded/pom.xml

Can we use this version instead?