Jib gradle 插件多模块项目 ClassNotFoundException

Jib gradle plugin multimodule project ClassNotFoundException

我有多模块 gradle 项目并使用 Jib 插件构建 docker 图像并推送到注册表。

但是,当我构建图像并尝试 运行 这个图像时,我得到了这个异常:

Error: Could not find or load main class Xmx512m

Caused by: java.lang.ClassNotFoundException: Xmx512m

这是我的根 build.gradle 文件:

plugins {
    id 'org.springframework.boot' version "$springBootVersion" apply false
    id 'io.spring.dependency-management' version "$springDependencyManagerVersion" apply false
    id 'com.google.cloud.tools.jib' version "$jlibVersion" apply false
}

def javaMicroservices = [
        project(':akt-user-management-ms'),
        project(':akt-applications-ms')
]

allprojects {
    repositories {
        mavenCentral()
        jcenter()
    }

    apply plugin: 'java'

    dependencies {
        implementation "io.jsonwebtoken:jjwt-api:${jwt_version}"
        implementation "io.jsonwebtoken:jjwt-impl:${jwt_version}"
        implementation "io.jsonwebtoken:jjwt-jackson:${jwt_version}"
    }
}

subprojects {
    sourceCompatibility = jdk_version
    targetCompatibility = jdk_version

    apply plugin: 'pmd'
    apply plugin: 'checkstyle'

    pmd {
        toolVersion = '6.10.0'
        ruleSets = []
        ignoreFailures = false
        rulePriority = 3
        ruleSetFiles = files("${rootProject.projectDir}/qa/pmd.xml")
    }

    checkstyle {
        toolVersion = '8.15'
        configFile = file("${rootProject.projectDir}/qa/checkstyle.xml")
        ignoreFailures = false
    }
    tasks.withType(Test) {
        maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
    }
}

configure(javaMicroservices) {
    apply plugin: 'com.google.cloud.tools.jib'

    jib {
        to {
            image = "$dockerRepoUrl/${project.name}"
        }
        container {
            jvmFlags = ['Xmx512m']
            creationTime = 'USE_CURRENT_TIMESTAMP'
        }
    }

}

根目录settings.gradle

rootProject.name = 'xxxx'
include 'akt-user-management-ms' //8080
include 'akt-applications-ms' //8081
include 'middleware' //8082
此项目之一的

build.gradle 文件。 (除了依赖性之外,它们都是相同的):

plugins {
    id 'org.springframework.boot'
    id 'io.spring.dependency-management'
    id 'java'
    id 'com.google.cloud.tools.jib'
}

group = 'az.ingress.user.management'
version = '0.0.1-SNAPSHOT'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation project(":common")

    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'

    implementation "io.springfox:springfox-swagger2:$swaggerVersion"
    implementation "io.springfox:springfox-swagger-ui:$swaggerVersion"

    implementation 'org.liquibase:liquibase-core'

    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'

    runtimeOnly 'mysql:mysql-connector-java'

    testImplementation 'org.springframework.security:spring-security-test'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

找不到任何解决方案。尝试了很多东西,但一遍又一遍地出现这个异常。

注意:使用jib版本:2.6.0

我从根 build.gradle 中删除了 jvmFlags = ['Xmx512m'],它按预期工作。

命令行选项通常以 --- 为前缀。在这种情况下应该是 -Xmx512m。没有 -java 会认为 Xmx512m 是 Java 主 class 名称。

$ java -Xmx512m com.example.HelloWorldMain
hello world
$ java foo
Error: Could not find or load main class foo
Caused by: java.lang.ClassNotFoundException: foo
$ java Xmx512m
Error: Could not find or load main class Xmx512m
Caused by: java.lang.ClassNotFoundException: Xmx512m