Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I get a metaspace error during my gradle build?

I sometimes get a metaspace error during my gradle build.

In my gradle configuration, I am using swagger code-gen to generate a lot of classes (~40). I guess that's probably where the problem comes from.

Here is an extract from the build.gradle file

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"

Here is an extract from the stacktrace (I replaced confidential things by %)

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
like image 700
Clemzd Avatar asked Feb 08 '19 11:02

Clemzd


1 Answers

You may increase the memory allocated to gradle in gradle.properties :

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m
like image 57
Gweltaz Niquel Avatar answered Sep 17 '22 11:09

Gweltaz Niquel