jib gradle插件多模块项目classnotfoundexception

vc6uscn9  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(460)

我有多模块gradle项目,并使用jib插件构建docker图像和推到注册表。
但是,当我构建映像并尝试运行此映像时,会出现以下异常:
错误:无法找到或加载主类xmx512m
原因:java.lang.classnotfoundexception:xmx512m
这是我的root 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'
        }
    }

}

根设置.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()
}

找不到任何解决方案。尝试了许多事情,但不断得到这个例外一遍又一遍。
注:使用起重臂版本:2.6.0

uklbhaso

uklbhaso1#

我从root build.gradle中删除了jvmflags=['xmx512m'],它按预期工作。

d6kp6zgx

d6kp6zgx2#

命令行选项通常以 - 或者 -- . 应该是的 -Xmx512m 在这种情况下。没有 - , java 会想 Xmx512m 是java主类名。

$ 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

相关问题