bmuschko / gradle-docker-plugin

Gradle plugin for managing Docker images and containers.
https://bmuschko.github.io/gradle-docker-plugin/current/user-guide/
Apache License 2.0
1.23k stars 362 forks source link

Error creating dockerCreateDockerfile #1106

Closed Bodden007 closed 2 years ago

Bodden007 commented 2 years ago

Hello friends. I'm still new to gradle and plugins. When trying to create a new dockerfile, when running the dockerCreateDockerfile task, i get an error. I try to do everything according to: https://bmuschko.github.io/gradle-docker-plugin/current/user-guide/#tasks_2.

`plugins { id 'org.springframework.boot' version '2.7.2' id 'io.spring.dependency-management' version '1.0.12.RELEASE' id 'java' id 'application' id "com.bmuschko.docker-spring-boot-application" version "8.1.0" }

tasks.withType(JavaCompile){ options.encoding = 'UTF-8' } tasks.jar {

    archiveBaseName = 'Revers_Bot'
    version = '1.0'

    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
        attributes 'Main-Class': 'reversbot.Main'
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

docker{
    springBootApplication{
        baseImage = 'openjdk:18.0.2-jdk-oracle'
        ports = [8080]
        images = ['java', '-jar',  'Bot.jar']
    }
}`

`sourceCompatibility = '18'

repositories { mavenCentral() mavenLocal() }

dependencies { implementation('org.springframework.boot:spring-boot-starter-web') compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.24' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' implementation 'com.vk.api:sdk:1.0.14' implementation group: 'javax.json', name: 'javax.json-api', version: '1.1.4' implementation group: 'org.glassfish', name: 'javax.json', version: '1.1.4' implementation 'com.google.guava:guava:31.1-jre'

}

configurations { all { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' } }

tasks.named('test') { useJUnitPlatform() }`

I get an error:

Unsupported Java. Your build is currently configured to use Java 18.0.2 and Gradle 7.5.1.

`Unsupported Java. Your build is currently configured to use Java 18.0.2 and Gradle 7.5.1.

Possible solution:

I can't understand why they don't want to be friends with cradle + plugin? The project is perfectly assembled in a jar and works.

bmuschko commented 2 years ago

I have a bunch of questions about the code you provided.

  1. The property named images on the springBootApplication extension should be a container image tag and not a list commands.
  2. Why do you need to mess with the jar task? The com.bmuschko.docker-spring-boot-application takes care of it.
  3. Port 8080 is the default so you won't need to set it.
  4. Please provide the stack trace of the error message by providing the -s command line option.
  5. You do not need the application plugin.
  6. Please properly format the your code snippet so that it becomes readable. Thanks!
bmuschko commented 2 years ago

This is what I tried:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.2'
    id 'io.spring.dependency-management' version '1.0.14.RELEASE'
    id 'com.bmuschko.docker-spring-boot-application' version '8.1.0'
}

docker {
    springBootApplication {
        baseImage = 'openjdk:18.0.2-jdk-oracle'
        images = ['spring-boot:1.0.0']
    }
}

version = '1.0.0'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(18)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
}

The error message I am see is something else than you are reporting.

Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 62
        at com.bmuschko.gradle.docker.shaded.org.objectweb.asm.ClassReader.<init>(ClassReader.java:196)
        at com.bmuschko.gradle.docker.shaded.org.objectweb.asm.ClassReader.<init>(ClassReader.java:177)
        at com.bmuschko.gradle.docker.shaded.org.objectweb.asm.ClassReader.<init>(ClassReader.java:163)
        at com.bmuschko.gradle.docker.shaded.org.objectweb.asm.ClassReader.<init>(ClassReader.java:284)

Is that what you are seeing?. If yes, then we have to upgrade the version of the ASM library that isn't compatible with Java 18 yet.

Bodden007 commented 2 years ago

Это то, что я пробовал:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.2'
    id 'io.spring.dependency-management' version '1.0.14.RELEASE'
    id 'com.bmuschko.docker-spring-boot-application' version '8.1.0'
}

docker {
    springBootApplication {
        baseImage = 'openjdk:18.0.2-jdk-oracle'
        images = ['spring-boot:1.0.0']
    }
}

version = '1.0.0'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(18)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
}

Сообщение об ошибке, которое я вижу, - это нечто иное, чем вы сообщаете.

Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 62
        at com.bmuschko.gradle.docker.shaded.org.objectweb.asm.ClassReader.<init>(ClassReader.java:196)
        at com.bmuschko.gradle.docker.shaded.org.objectweb.asm.ClassReader.<init>(ClassReader.java:177)
        at com.bmuschko.gradle.docker.shaded.org.objectweb.asm.ClassReader.<init>(ClassReader.java:163)
        at com.bmuschko.gradle.docker.shaded.org.objectweb.asm.ClassReader.<init>(ClassReader.java:284)

Это то, что вы видите?. Если да, то нам нужно обновить версию библиотеки ASM, которая еще не совместима с Java 18.

Thank you, you're right. That's exactly what I see. Can I somehow update the ASM library ?

bmuschko commented 2 years ago

In this case, you can't upgrade the library as it has been bundled and package-relocated in the plugin JAR. The change will go out with the next release of the plugin: https://github.com/bmuschko/gradle-docker-plugin/pull/1107

bmuschko commented 2 years ago

Side note: I'd recommend just sticking with Java 17 which is the Long Term Support release of Java. I doubt there's a specific feature or bug fix in Java 18 that you need specifically.

Bodden007 commented 2 years ago

I get it, thanks.