Maven process-test-aot only copies META-INF/native-image of the generated resources so the Logback configuration is lost in native tests
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
- Ambito
- build-system, testing
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
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:
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:
and the Gradle plugin adds the whole generated resources directory to the aotTest source set:
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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di spring-projects/spring-boot
-
status: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
spring-projects/spring-boot#52316 ·
I maintainer di solito rispondono entro 2 giorni
-
status: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
spring-projects/spring-boot#52300 ·
I maintainer di solito rispondono entro 2 giorni
-
status: waiting-for-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
spring-projects/spring-boot#52296 ·
I maintainer di solito rispondono entro 2 giorni
-
status: waiting-for-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
spring-projects/spring-boot#52295 ·
I maintainer di solito rispondono entro 2 giorni
-
status: team-only type: task
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
spring-projects/spring-boot#52143 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di spring-projects/spring-boot
Issue simili
-
enhancement web-ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
jenkinsci/jenkins#27583 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/rocketmq-dashboard#7302 ·
I maintainer di solito rispondono entro 3 giorni
-
area: android good first issue help wanted testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Gautam-aman/ResQNet#56 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation hermes-queue
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
chrisalunlloyd2-sudo/mindpalace#294 ·
I maintainer di solito rispondono entro 1 giorno