Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Compilation Error: org.springframework.cloud.sleuth.autoconfig._FactoryProvider issue #673

Closed
AndersClausen opened this issue Mar 26, 2021 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@AndersClausen
Copy link

Hi

I'm using spring-native 0.9.1, spring-boot 2.4.4 and java 11 and when I run mvn spring-boot:build-image I get the following error and not sure how to fix it.
The project builds fine if I remove spring-cloud-sleuth from it but I thought Sleuth was now working with spring-native based on Marcin's fix in #614.

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /F:/work/azure/shipment-management/billoflading-summary/target/generated-test-sources/spring-aot/src/test/java/org/springframework/cloud/sleuth/autoconfig/_FactoryProvider.java:[8,47] method traceEnvironmentPostProcessor() is already defined in class org.springframework.cloud.sleuth.autoconfig._Fac
toryProvider
[ERROR] /F:/work/azure/shipment-management/billoflading-summary/target/generated-test-sources/spring-aot/src/test/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/client/_FactoryProvider.java:[8,54] method traceGatewayEnvironmentPostProcessor() is already defined in class org.springframework
.cloud.sleuth.autoconfig.instrument.web.client._FactoryProvider
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[ERROR] org.apache.maven.plugin.MojoExecutionException: Unable to execute mojo
[ERROR] [org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo(MojoExecutor.java:122), org.springframework.aot.maven.AbstractBootstrapMojo.compileGeneratedTestSources(AbstractBootstrapMojo.java:159), org.springframework.aot.maven.TestGenerateMojo.execute(TestGenerateMojo.java:66), org.apache.maven.plugin.
DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137), org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210), org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156), org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.
java:148), org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:355), org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:200), org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156), org.apache.maven.lifecycle.internal.M
ojoExecutor.execute(MojoExecutor.java:148), org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117), org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81), org.apache.maven.lifecycle.internal.builder.singleth
readed.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56), org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128), org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305), org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192), org.apache.maven.Defaul
tMaven.execute(DefaultMaven.java:105), org.apache.maven.cli.MavenCli.execute(MavenCli.java:957), org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289), org.apache.maven.cli.MavenCli.main(MavenCli.java:193), java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method), java.base/jdk.inte
rnal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62), java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43), java.base/java.lang.reflect.Method.invoke(Method.java:566), org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhan
ced(Launcher.java:282), org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225), org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406), org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  56.653 s
[INFO] Finished at: 2021-03-26T12:44:10Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.experimental:spring-aot-maven-plugin:0.9.1:test-generate (test-generate) on project billoflading-summary: Build failed during Spring AOT test code generation: Unable to execute mojo: Compilation failure:
[ERROR] /F:/work/azure/shipment-management/billoflading-summary/target/generated-test-sources/spring-aot/src/test/java/org/springframework/cloud/sleuth/autoconfig/_FactoryProvider.java:[8,47] method traceEnvironmentPostProcessor() is already defined in class org.springframework.cloud.sleuth.autoconfig._Fac
toryProvider
[ERROR] /F:/work/azure/shipment-management/billoflading-summary/target/generated-test-sources/spring-aot/src/test/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/client/_FactoryProvider.java:[8,54] method traceGatewayEnvironmentPostProcessor() is already defined in class org.springframework
.cloud.sleuth.autoconfig.instrument.web.client._FactoryProvider
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Thanks for all your help - it's great what you're doing here.

@bclozel bclozel self-assigned this Mar 26, 2021
@bclozel bclozel added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 26, 2021
@bclozel
Copy link
Contributor

bclozel commented Mar 26, 2021

Hi @AndersClausen

Do you have a minimal, sample application we could take a look at? Something we can git clone or download would be great.

Thanks!

@AndersClausen
Copy link
Author

Hi @bclozel

This a microservice from my company, so I'll try and see if I can get it recreated in simpler service and make it publicly available.

Cheers

@AndersClausen
Copy link
Author

@bclozel Here is a very simple app https://github.com/AndersClausen/sleuth-issue that will demonstrate the issue.

Please let me know if you need anything further. Thanks!

bclozel added a commit to bclozel/spring-native that referenced this issue Apr 9, 2021
Prior to this commit the AOT processing of Spring Factories would
consider duplicate factories definitions (if by mistake a factory is
defined twice in separate spring.factories files) and generate invalid
code.

This commit skips duplicate factories definitions.

Fixes spring-atticgh-673
@bclozel bclozel added this to the 0.9.2 milestone Apr 9, 2021
@bclozel bclozel added theme: aot type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 9, 2021
@bclozel
Copy link
Contributor

bclozel commented Apr 9, 2021

Thanks @AndersClausen for this sample, this is super useful as always.

We've found that a spring factory was somehow defined twice, generating invalid AOT source code. We're now more defensive and avoid such problems. We've also raised spring-projects-experimental/spring-cloud-sleuth-otel#42 to fix the root cause.

I've tried to build the native image with the sample project you've provided and now I'm getting a different issue. I'll create a new issue for that if necessary.

2021-04-09 09:34:37.342 ERROR [,,] 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Unable to read meta-data for class org.springframework.cloud.sleuth.autoconfig.instrument.quartz.TraceQuartzAutoConfiguration
	at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getAnnotationMetadata(AutoConfigurationSorter.java:237) ~[na:na]
	at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.getOrder(AutoConfigurationSorter.java:208) ~[na:na]
	at org.springframework.boot.autoconfigure.AutoConfigurationSorter$AutoConfigurationClass.access$000(AutoConfigurationSorter.java:154) ~[na:na]
	at org.springframework.boot.autoconfigure.AutoConfigurationSorter.lambda$getInPriorityOrder$0(AutoConfigurationSorter.java:63) ~[na:na]

@bclozel
Copy link
Contributor

bclozel commented Apr 9, 2021

I'm closing this issue and I've opened a follow-up for this sample: #718

@bclozel bclozel closed this as completed Apr 9, 2021
bclozel added a commit that referenced this issue Apr 9, 2021
Prior to this commit the AOT processing of Spring Factories would
consider duplicate factories definitions (if by mistake a factory is
defined twice in separate spring.factories files) and generate invalid
code.

This commit skips duplicate factories definitions.

Fixes gh-673
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

2 participants