Почему я получаю ошибку метапространства во время сборки Gradle? - PullRequest
0 голосов
/ 08 февраля 2019

Я иногда получаю ошибку метапространства во время сборки gradle.

В конфигурации gradle я использую swagger code-gen для генерации большого количества классов (~ 40).Я думаю, что, вероятно, в этом и заключается проблема.

Вот выдержка из файла build.gradle

dependencies {
    ...
    implementation("io.swagger:swagger-annotations:1.5.10")
    implementation("io.springfox:springfox-swagger2:2.9.2")
    swaggerCodegen("io.swagger.codegen.v3:swagger-codegen-cli:3.0.0")
}
...
swaggerSources {
    doe1 {
        inputFile = file('src/main/resources/wiremock/gfc/yaml/doe-1.yaml')
        code {
            language = 'spring'
            components = ['models']
            additionalProperties = ["modelPackage": "io.swagger.model.doe1", "invokerPackage": "io.swagger.model"]
        }
    }
    doe2 {
        inputFile = file('src/main/resources/wiremock/gfc/yaml/doe-2.yaml')
        code {
            language = 'spring'
            components = ['models']
            additionalProperties = ["modelPackage": "io.swagger.model.doe2", "invokerPackage": "io.swagger.model"]
        }
    }
    ...

    doe40 {
        inputFile = file('src/main/resources/wiremock/gfc/yaml/doe-40.yaml')
        code {
            language = 'spring'
            components = ['models']
            additionalProperties = ["modelPackage": "io.swagger.model.doe3", "invokerPackage": "io.swagger.model"]
        }
    }
}


compileJava.dependsOn swaggerSources.doe1.code, swaggerSources.doe2.code, ....., swaggerSources.doe40.code
sourceSets.main.java.srcDirs "${swaggerSources.doe1.code.outputDir}/src/main/java", "${swaggerSources.doe2.code.outputDir}/src/main/java", ..., "${swaggerSources.doe40.code.outputDir}/src/main/java"
sourceSets.main.resources.srcDirs "${swaggerSources.doe1.code.outputDir}/src/main/resources", "${swaggerSources.doe2.code.outputDir}/src/main/resources", ..., "${swaggerSources.doe40.code.outputDir}/src/main/resources"

Вот выдержка из трассировки стека (я заменил конфиденциальные данные на%)

Testing started at 15:35 ...
15:35:11: Executing tasks 'cleanTest test build ry,exceptions=disable,delay=10000'...

> Configure project :%%%%%repo:%%%%%-common   
> Task :%%%%%repo:%%%%%-%%%:cleanTest UP-TO-DATE
> Task :%%%%%repo:%%%%%-common:cleanTest UP-TO-DATE
.....
> Task :%%%%%repo:%%%%%-common:resolveSwaggerTemplate NO-SOURCE
> Task :%%%%%repo:%%%%%-common:generateSwagger%%%%%%%%%diffusionapi FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':%%%%%repo:%%%%%-common:generateSwagger%%%%%%%%%%%diffusionapi'.
> Metaspace
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':%%%%%repo:%%%%%-common:generateSwaggerCode%%%%diffusionapi'.
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:119)
    at ..
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    Caused by: java.lang.OutOfMemoryError: Metaspace
    BUILD FAILED in 3s
    26 actionable tasks: 1 executed, 25 up-to-date
    Cause: invalid type code: 5F

1 Ответ

0 голосов
/ 14 февраля 2019

Вы можете увеличить объем памяти, выделенной для gradle:

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m
...