Skip to content

Commit 818c800

Browse files
fix: exclude ByteBuddy from nativeCompile classpath to resolve ServiceConfigurationError in native image
Agent-Logs-Url: https://github.com/EspacoGeek-Teams/SpringAPI_EspacoGeek/sessions/90c7e0c9-b892-4c86-bb53-891ec3334291 Co-authored-by: vitorhugo-java <65777252+vitorhugo-java@users.noreply.github.com>
1 parent b3600fb commit 818c800

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ tasks.named('bootWar') {
163163
enabled = true
164164
}
165165

166+
// ByteBuddy cannot generate bytecode at native-image runtime.
167+
// Hibernate 6.6 calls loadJavaServices(BytecodeProvider.class) unconditionally
168+
// (before honouring hibernate.bytecode.provider=none), so the provider is
169+
// instantiated and fails. Build-time Hibernate enhancement (see 'hibernate {}'
170+
// block below) replaces every runtime enhancement, making ByteBuddy unnecessary
171+
// in the native image. Tests are not affected because they run on the JVM with
172+
// their own classpath that still resolves byte-buddy through Mockito.
173+
tasks.named('nativeCompile') {
174+
doFirst {
175+
options.classpath.setFrom(
176+
options.classpath.filter { !it.name.startsWith('byte-buddy-') }
177+
)
178+
}
179+
}
180+
166181
bootRun {
167182
if ((System.getenv('NATIVE_IMAGE_AGENT') ?: 'false').toBoolean()) {
168183
def hintsDir = System.getenv('NATIVE_IMAGE_HINTS_DIR') ?: 'build/native-image-hints'

0 commit comments

Comments
 (0)