Transmode / gradle-docker

A Gradle plugin to build Docker images from the build script.
Apache License 2.0
647 stars 142 forks source link

Building on java 9 raises an exception #129

Closed dvallin closed 6 years ago

dvallin commented 6 years ago

In our gradle file we have (among lots of other things)

task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'se.transmode.gradle:gradle-docker:1.2'
    }
}

targetCompatibility = 9

docker {
    baseImage "openjdk:9-jre"
}

task buildDocker(type: Docker, dependsOn: build) {
    version = versionDetails().gitHash
    applicationName = rootProject.name.toLowerCase()
    entryPoint(['java', '-jar', "${jar.archiveName}"])
    addFile {
        from jar
    }
}

running ./gradlew buildDocker gives an error message

Execution failed for task ':service:buildDocker'.
> No Java base image for the supplied target 1.9 found.

This would be the expected behavior for not configuring a baseImage. But if we set the targetCompatibility to 1.8 the image builds fine with:

Step 1/3 : FROM openjdk:9-jre
 ---> 684d13528523
Step 2/3 : ENTRYPOINT java -jar service-6b91d17906.jar
 ---> Using cache
 ---> 1474d66a7574
Step 3/3 : ADD add_2.tar /
 ---> 9c2a11d2f78b
Successfully built 9c2a11d2f78b

So the baseImage is picked up after all!

See pull request https://github.com/Transmode/gradle-docker/pull/128

dvallin commented 6 years ago

We decided to include a Dockerfile instead of using the DSL

task buildDocker(type: Docker) {
    dockerfile = 'Dockerfile'
    version = versionDetails().gitHash
    applicationName = rootProject.name.toLowerCase()
    entryPoint(['java', '-jar', "${jar.archiveName}"])
    addFile {
        from jar
    }
}

with a Dockerfile as simple as

FROM openjdk:9-jre

now it works with even with targetCompatibility = 9

NaikSoftware commented 5 years ago

Same error with any JDK > 8

benparvar commented 4 years ago

We decided to include a Dockerfile instead of using the DSL

task buildDocker(type: Docker) {
    dockerfile = 'Dockerfile'
    version = versionDetails().gitHash
    applicationName = rootProject.name.toLowerCase()
    entryPoint(['java', '-jar', "${jar.archiveName}"])
    addFile {
        from jar
    }
}

with a Dockerfile as simple as

FROM openjdk:9-jre

now it works with even with targetCompatibility = 9

This works fine!!!!

Thanks