在构建gradle时有时会出现元空间错误。
在gradle配置中,我使用了摇摇欲坠的代码生成了很多类(〜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
答案 0 :(得分:1)
您可以增加分配给gradle的内存:
fun updatePostView() =
apiService.getPost(view.postId)
.subscribeOn(Schedulers.io())
.map { it.first() }
.createPostDetails()
.observeOn(view.scheduler)
.subscribeBy(
onNext = { view.showDetails(it) },
onError = { it.printStackTrace() }
)
private fun Observable<out Post>.createPostDetails(): Observable<PostDetails> =
flatMap { post ->
Observables.zip(
getPostTitle(post),
getPostBody(post),
getPostUser(post),
getPostComments(post)
) { title, body, name, comments -> PostDetails(title, body, name, comments) }
}
private fun getPostTitle(post: Post) =
Observable.just(post.title)
private fun getPostBody(post: Post) =
Observable.just(post.body)
private fun getPostUser(post: Post) =
apiService.getUser(post.userId).subscribeOn(Schedulers.io()).map { it.first().username }
private fun getPostComments(post: Post) =
apiService.getComments(post.id).subscribeOn(Schedulers.io()).map { it.size.toString() }