Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Maven process-test-aot only copies META-INF/native-image of the generated resources so the Logback configuration is lost in native tests

Aperta Adatta ai principianti
#52,301 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java, spring-boot

Direzione di ricerca

Inizia leggendo ProcessTestAotMojo.java intorno alla chiamata a copyAll alle righe 138–139, poi confrontalo con ProcessAotMojo e con il comportamento del plugin AOT Gradle citato nell’issue. Esegui mvn -PnativeTest test nella riproduzione di esempio per confermare che META-INF/spring/logback-model manca dalle classi di test; il lavoro è completato quando le risorse AOT di test vengono copiate e il test nativo usa l’appender Logback configurato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

status: waiting-for-triage

Spring Boot 4.1.1, Maven, GraalVM 25 (the plugin code in question is unchanged since 3.0).

With a custom logback-spring.xml, tests that run as a native image (mvn -PnativeTest test) are not configured with it,
Logback falls back to Spring Boot's defaults. On the JVM and in the native image of the application the configuration is
applied.

During test AOT processing, SpringBootJoranConfigurator writes the Logback model to
target/spring-aot/test/resources/META-INF/spring/logback-model and registers a resource hint for it. However,
ProcessTestAotMojo only copies the META-INF/native-image directory of the generated resources into the test classes
directory:

https://github.com/spring-projects/spring-boot/blob/v4.1.1/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java#L138-L139

copyAll(this.generatedResources.toPath().resolve("META-INF/native-image"),
        this.testClassesDirectory.toPath().resolve("META-INF/native-image"));

As a result, META-INF/spring/logback-model isn't part of the native test image.
LogbackLoggingSystem.initializeFromAotGeneratedArtifactsIfPossible finds no model and falls back to the regular
initialization. That doesn't find logback-spring.xml either (the image has no resource hint for it), so the defaults
are applied.

ProcessAotMojo copies all generated resources:

https://github.com/spring-projects/spring-boot/blob/v4.1.1/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessAotMojo.java#L115

and the Gradle plugin adds the whole generated resources directory to the aotTest source set:

https://github.com/spring-projects/spring-boot/blob/v4.1.1/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootAotPlugin.java#L221

so I'd expect process-test-aot to copy all generated resources into the test classes directory as well.

Sample

https://github.com/darya-lap/spring-boot-test-aot-logback-repro/tree/main — spring-boot-starter, spring-boot-starter-test, a logback-spring.xml with an
appender REPRO and a @SpringBootTest that checks the root logger has the appender REPRO and not CONSOLE.

mvn test               # passes
mvn -PnativeTest test  # fails

After mvn -PnativeTest test, target/spring-aot/test/resources/META-INF/spring/logback-model exists but
target/test-classes/META-INF/spring/logback-model doesn't.

Workaround

Copy the generated resources into the test classes after process-test-aot:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-test-aot-resources</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.testOutputDirectory}/META-INF/spring</outputDirectory>
                <resources>
                    <resource>
                        <directory>${project.build.directory}/spring-aot/test/resources/META-INF/spring</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>
Lingua principale
Java
Stelle
81.7k
Fork
45.1k
Merge medio
2g 14h
PR unite (30g)
44

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di spring-projects/spring-boot

Tutte le issue di spring-projects/spring-boot

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.