Closed lhmoraes closed 3 years ago
Thanks @MarcelCoding
Added the dependency:
implementation("org.springframework.experimental:spring-native:0.9.0")
But I'm still getting the same error:
[creator] Error: Classes that should be initialized at run time got initialized during image building:
[creator] org.springframework.util.unit.DataSize was unintentionally initialized at build time. To see why org.springframework.util.unit.DataSize got initialized use --trace-class-initialization=org.springframework.util.unit.DataSize
You also need the aot plugin https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#spring-aot-gradle
Yes, its already there:
id("org.springframework.experimental.aot") version "0.9.0"
Yes, its already there:
id("org.springframework.experimental.aot") version "0.9.0"
Ohh, sorry I missed it. Do you have you project on a public GitHub repository or something similar?
No, sorry, that is a private repo, a project from my company, but I can provide some information that you need
@lhmoraes I'm sorry but in this case the devil is in the details. It looks like this is a multi-module project. We already fixed a similar issue and the actual source of the problem can be really hard to diagnose by comments in an issue.
Could you create a minimal, sample project that reproduces this behavior? Given that the AOT processing doesn't seem to be involved at all this should be obvious once it's ready. Copying the multi-module aspect of the build and possibly build plugins involved should be a good start.
Thanks!
You are correct @bclozel its a multi-module project, please see below my main and modules build.gradle:
Main build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
import org.jetbrains.kotlin.kapt3.base.Kapt.kapt
plugins {
id("org.springframework.boot") version "2.4.3"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.springframework.experimental.aot") version "0.9.0"
kotlin("jvm") version "1.4.30"
kotlin("plugin.spring") version "1.4.30"
kotlin("kapt") version "1.4.30"
base
java
}
allprojects {
// Apply plugins for the all sub-projects .......................
apply(plugin = "java")
apply(plugin = "base")
apply(plugin = "kotlin")
apply(plugin = "kotlin-spring")
apply(plugin = "kotlin-kapt")
apply(plugin = "org.springframework.boot")
apply(plugin = "io.spring.dependency-management")
// Project configuration ........................................
val PROJECT_GROUP = "xxxxxxxxx"
val PROJECT_VERSION = "1.0.RELEASE"
val SPRING_CLOUD_VERSION = "2020.0.1"
val SPRING_DOC_OPENAPI_VERSION = "1.5.4"
val COMMON_VERSION = "4.0.RELEASE"
val MAPSTRUCT_VERSION = "1.4.2.Final"
val SENTRY_VERSION = "4.2.0"
val R2DBC_MARIADB_VERSION = "1.0.0"
val WAVEFRONT_VERSION = "2.1.0"
val LOKI_VERSION = "1.1.0"
val JODA_VERSION = "2.10.1"
val IMAGE_NAME = "xxxxxxxxx"
val REGISTRY_URL = "xxxxxxxxx"
val REGISTRY_USERNAME = "xxxxxxxxx"
val REGISTRY_PASSWORD = "xxxxxxxxx"
val REGISTRY_CONTACT = "xxxxxxxxx"
// Project group and version configuration .......................
group = PROJECT_GROUP!!
version = PROJECT_VERSION!!
base.archivesBaseName = rootProject.name
java.sourceCompatibility = JavaVersion.VERSION_11
// Dependencies Libraries .........................................
dependencies {
// Company Common Lib .................
implementation("xxxxxxxxxxxx:${COMMON_VERSION}")
// Spring Framework ..........
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.springframework.cloud:spring-cloud-starter-sleuth")
developmentOnly("org.springframework.boot:spring-boot-devtools")
// Spring Native Image ..............
implementation("org.springframework.experimental:spring-native:0.9.0")
// Spring Kubernetes ................
implementation("org.springframework.cloud:spring-cloud-starter-kubernetes-client-config")
implementation("org.springframework.cloud:spring-cloud-kubernetes-fabric8-istio")
// Kotlin ....................
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
// Micrometer Prometheus ......
runtimeOnly("io.micrometer:micrometer-registry-prometheus")
// Jackson ...................
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
// Wavefront .................
implementation("com.wavefront:wavefront-spring-boot-starter")
// MariaDB ...................
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
runtimeOnly("org.mariadb:r2dbc-mariadb:${R2DBC_MARIADB_VERSION}")
// Loki Grafana Logging.......
implementation ("com.github.loki4j:loki-logback-appender:${LOKI_VERSION}")
// Sentry ....................
implementation("io.sentry:sentry-logback:${SENTRY_VERSION}")
// MapStruct .................
implementation("org.mapstruct:mapstruct:${MAPSTRUCT_VERSION}")
kapt("org.mapstruct:mapstruct-processor:${MAPSTRUCT_VERSION}")
// Joda Date Time ..............
//implementation("joda-time:joda-time:${JODA_VERSION}")
// SpringDoc-OpenApi .........
implementation("org.springdoc:springdoc-openapi-webflux-ui:${SPRING_DOC_OPENAPI_VERSION}")
implementation("org.springdoc:springdoc-openapi-kotlin:${SPRING_DOC_OPENAPI_VERSION}")
// Apache Commons ............
implementation("commons-io:commons-io:2.6")
// Spring Test ...............
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
}
// Spring Cloud dependency management .....................................
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${SPRING_CLOUD_VERSION}")
mavenBom("com.wavefront:wavefront-spring-boot-bom:${WAVEFRONT_VERSION}")
}
}
// Dependencies repositories .....................................
repositories {
maven { url = uri( "https://repo.spring.io/release") }
maven { url = uri( "https://repo.spring.io/milestone") }
maven { url = uri( "https://repo.spring.io/snapshot") }
mavenCentral()
}
// Tasks ..................................................................
tasks {
withType<Test> {
useJUnitPlatform()
}
withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = java.sourceCompatibility.toString()
}
}
// Image: Build the image and publish it to the private parlacom registry
withType<BootBuildImage> {
builder = "paketobuildpacks/builder:tiny"
environment = mapOf("BP_NATIVE_IMAGE" to "true")
imageName = IMAGE_NAME
isPublish = true
docker {
publishRegistry {
username = REGISTRY_USERNAME
password = REGISTRY_PASSWORD
url = REGISTRY_URL
email = REGISTRY_CONTACT
}
}
}
}
}
Module build.gradle.kts
import org.springframework.boot.gradle.tasks.bundling.BootJar
// Module group and version configuration .................................
base.archivesBaseName = "${rootProject.name}-${project.name.substring(4)}"
// Tasks ..................................................................
tasks.getByName<BootJar>("bootJar") {
enabled = false
}
tasks.getByName<Jar>("jar") {
enabled = true
}
Interesting.
Any particular reason behind the bootJar
task being disabled by your build?
Currently our build plugin is relying on that task to package the AOT generated classes with the application. This would explain why they're missing when we're building the container image.
Could you try and activate it to check whether this fixes the problem?
@bclozel enabled it, but I'm getting the same error:
tasks.getByName<BootJar>("bootJar") {
enabled = true
}
Error:
[creator] Error: Classes that should be initialized at run time got initialized during image building:
[creator] org.springframework.util.unit.DataSize was unintentionally initialized at build time. To see why org.springframework.util.unit.DataSize got initialized use --trace-class-initialization=org.springframework.util.unit.DataSize
In this case, we're definitely going to need a sample project that we can clone or download so that we can work on this.
Thanks @bclozel I will create a sample project and publish it in a public repository
Hi @bclozel I've pushed a sample project that describes the error. Please, just execute bootBuildImage to simulate the issue.
https://github.com/lhmoraes/sb-native-image
Thanks and just let me know if you need more information.
Thanks @lhmoraes for the sample. Unfortunately it wasn't really minimal, so there was a lot to unpack here.
First, the "org.springframework.experimental.aot"
plugin was only applied on the parent project, but not on the actual module that builds the Spring Boot application and the docker image. Applying it to the right module would solve the main problem here.
As a general feedback, the Spring Boot plugin should only be applied on the module where the main class lives. Same for the AOT plugin, which is a companion plugin in this case.
Also, the sample was depending on Spring Boot devtools (see #532) and Sleuth (see #135) - they're not supported yet.
The sample also depends on Spring Cloud Kubernetes, bringing OkHttp (requiring UTF-32BE encoding) and using HttpStatus
reflection in some other part (see #612). Both problems can be solved with the following annotations on the main class:
@NativeHint(options = ["-H:+AddAllCharsets"])
@TypeHint(types = [HttpStatus::class])
Of course, it's hard to figure out the changes from this comment. I've submitted a PR to your sample that moves things forward. This might need a bit more work but I think we've covered the main report here.
Besides all the linked issues here, we'll help developers with multi-module projects with a sample in #611. I'm closing this issue for now since other, more focused issues, are already covering things.
Thanks!
Thanks @bclozel it's much better now, I will continue to work on the issues
Hi, i see that my poc is pretty similar to mentioned on this issue, however, i dont know why its throwing 145 on build, i raised me to 12GB, however still happing, could you take a look?
[INFO] [creator] at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183) [INFO] [creator] Error: Image build request failed with exit status 1 [INFO] [creator] unable to invoke layer creator [INFO] [creator] unable to contribute native-image layer [INFO] [creator] error running build [INFO] [creator] exit status 1 [INFO] [creator] ERROR: failed to build: exit status 1 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 05:45 min [INFO] Finished at: 2021-05-24T23:49:40+02:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.5:build-image (default-cli) on project anagram: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.5:build-image failed: Builder lifecycle 'creator' failed with status code 145 -> [Help 1] [ERROR]
repo: https://github.com/nekperu15739/anagram/tree/feature/kuberneter
@nekperu15739 I can build it without an issue on my computer, and it shows the following error:
The bean 'anagramHandler' could not be injected as a 'com.nekperu15739.anagram.handler.AnagramHandler' because it is a JDK dynamic proxy that implements
Execution failed for task ':mod-rest-app:bootBuildImage'.