Skip to content

Repeated invocation of AOT phase breaks creation of application-modules.json #1457

@Gadnex

Description

@Gadnex

I created a new project with Spring Initializer with Spring Boot 4.0.0-RC2

I am using the following relevant Gradle definition.

plugins {
	id 'org.graalvm.buildtools.native' version '0.11.2'
}

dependencies {
   implementation 'org.springframework.modulith:spring-modulith-starter-core'
   implementation 'org.springframework.boot:spring-boot-starter-actuator'
   runtimeOnly 'org.springframework.modulith:spring-modulith-actuator'
   runtimeOnly 'org.springframework.modulith:spring-modulith-observability'
}

Initially everything starts up and works well.

As soon as I set the Spring Actuator port to a different port my application fails to start up:

management:
  server:
    port: 9080

The error I get is:

Exception in thread "main" org.springframework.beans.factory.aot.AotBeanProcessingException: Error processing bean with name 'childManagementContextInitializer' defined in class path resource [org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextAutoConfiguration$DifferentManagementContextConfiguration.class]: failed to generate code for bean definition
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.lambda$generateRegisterBeanDefinitionMethods$0(BeanRegistrationsAotContribution.java:280)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.generateRegisterBeanDefinitionMethods(BeanRegistrationsAotContribution.java:270)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.generateBeanRegistrationsCode(BeanRegistrationsAotContribution.java:238)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.lambda$generateBeanRegistrationClass$0(BeanRegistrationsAotContribution.java:116)
        at org.springframework.aot.generate.GeneratedMethod.<init>(GeneratedMethod.java:54)
        at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:112)
        at org.springframework.aot.generate.GeneratedMethods.add(GeneratedMethods.java:89)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.generateBeanRegistrationClass(BeanRegistrationsAotContribution.java:110)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.generateBeanRegistrationCode(BeanRegistrationsAotContribution.java:88)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.applyTo(BeanRegistrationsAotContribution.java:77)
        at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:94)
        at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:59)
        at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:68)
        at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:54)
        at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:107)
        at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
        at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
        at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:84)
        at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:96)
Caused by: java.lang.IllegalStateException: /home/gadnex/Documents/VSCodeProjects/narrator/build/generated/aotResources/META-INF/spring-modulith/application-modules.json already exists
        at org.springframework.aot.generate.GeneratedFiles$FileHandler.create(GeneratedFiles.java:279)
        at org.springframework.aot.generate.GeneratedFiles.lambda$addFile$1(GeneratedFiles.java:170)
        at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60)
        at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:49)
        at org.springframework.aot.generate.FileSystemGeneratedFiles.handleFile(FileSystemGeneratedFiles.java:90)
        at org.springframework.aot.generate.GeneratedFiles.addFile(GeneratedFiles.java:170)
        at org.springframework.aot.generate.GeneratedFiles.addFile(GeneratedFiles.java:155)
        at org.springframework.aot.generate.GeneratedFiles.addResourceFile(GeneratedFiles.java:109)
        at org.springframework.aot.generate.GeneratedFiles.addResourceFile(GeneratedFiles.java:98)
        at org.springframework.modulith.runtime.autoconfigure.ApplicationModulesFileGeneratingProcessor.lambda$processAheadOfTime$1(ApplicationModulesFileGeneratingProcessor.java:56)
        at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:94)
        at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:59)
        at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:68)
        at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:54)
        at org.springframework.boot.actuate.autoconfigure.web.server.ChildManagementContextInitializer$AotContribution.applyTo(ChildManagementContextInitializer.java:198)
        at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.lambda$generateBeanDefinitionMethod$0(BeanDefinitionMethodGenerator.java:165)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
        at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.generateBeanDefinitionMethod(BeanDefinitionMethodGenerator.java:165)
        at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.generateBeanDefinitionMethod(BeanDefinitionMethodGenerator.java:89)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.generateBeanRegistration(BeanRegistrationsAotContribution.java:289)
        at org.springframework.beans.factory.aot.BeanRegistrationsAotContribution$BeanDefinitionsRegistrationGenerator.lambda$generateRegisterBeanDefinitionMethods$0(BeanRegistrationsAotContribution.java:272)
        ... 19 more

I can get things to work if I disable (comment out) the GraalVM native builds, but the following combination of architecture choices are important to me:

  • Use Spring Modulith
  • Compile to a GraalVM native image
  • Use Spring Actuator on a different management port.

Metadata

Metadata

Assignees

Labels

in: runtimeGeneral runtime supporttype: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions