spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.94k stars 40.64k forks source link

Compile time weaving breaks with spring-boot-configuration-processor #4825

Closed jmirc closed 8 years ago

jmirc commented 8 years ago

I have a project using AspectJ and enabled the spring-boot-configuration-processor plugin.

SpringBoot: 1.3 AspectJ: 1.8.6 Maven: Multiple modules

When I compile my project using maven, I got the following exception

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ change-notification ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 17 source files to /Users/jmirc/dev/2-content-system/multisource-assembly/change-notification/target/classes
[INFO] 
[INFO] --- aspectj-maven-plugin:1.8:compile (default) @ change-notification ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[WARNING] bad version number found in /Users/jmirc/.m2/repository/org/aspectj/aspectjrt/1.8.6/aspectjrt-1.8.6.jar expected 1.8.7 found 1.8.6
    <unknown source file>:<no line information>

[WARNING] Field value processing of @ConfigurationProperty meta-data is not supported
    <unknown source file>:<no line information>

javax.annotation.processing.FilerException: Resource already created : CLASS_OUTPUT//META-INF/spring-configuration-metadata.json
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchFilerImpl.createResource(BatchFilerImpl.java:90)
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AjBatchFilerImpl.createResource(AjBatchFilerImpl.java:35)
    at org.springframework.boot.configurationprocessor.MetadataStore.createMetadataResource(MetadataStore.java:109)
    at org.springframework.boot.configurationprocessor.MetadataStore.writeMetadata(MetadataStore.java:69)
    at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.writeMetaData(ConfigurationMetadataAnnotationProcessor.java:364)
    at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.process(ConfigurationMetadataAnnotationProcessor.java:138)
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:140)
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:111)
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159)
    at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:962)
    at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:434)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1036)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:272)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:185)
    at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:114)
    at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
    at org.aspectj.tools.ajc.Main.run(Main.java:371)
    at org.aspectj.tools.ajc.Main.runMain(Main.java:248)
    at org.codehaus.mojo.aspectj.AbstractAjcCompiler.execute(AbstractAjcCompiler.java:537)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
snicoll commented 8 years ago

Does it matter if it's a multi-modules project (since you mentioned it explicitly). It would help if you could share a sample or at least your maven-compiler-plugin configuration (I can see you're using APT and I'd like to know if you get the same error with the standard compiler).

jmirc commented 8 years ago

I will try to share a sample soon.

Here are our maven configuration.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
    </configuration>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.8</version>
    <configuration>
        <Xlint>ignore</Xlint>
        <complianceLevel>1.8</complianceLevel>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>expedia.content.solutions.metrics</groupId>
                <artifactId>aspectj-support</artifactId>
            </aspectLibrary>
        </aspectLibraries>
        <includes>
            <include>**/*.java</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>
snicoll commented 8 years ago

that does not help much I am afraid, there is nothing that indicates where JDT comes from. Or do you get that issue when you compile in Eclipse or something?

Actually scratch that, the aspectJ compiler is running the annotation processor and it runs again with the regular compiler I guess.

jmirc commented 8 years ago

It was an issue in our pom.xml. Sorry for the spam.

snicoll commented 8 years ago

can you share what the issue was please?

jmirc commented 8 years ago

I just updated the aspectJ plugin

               <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <version>1.8</version>
                    <configuration>
                        <showWeaveInfo/>
                        <forceAjcCompile>true</forceAjcCompile>
                        <Xlint>ignore</Xlint>
                        <complianceLevel>1.8</complianceLevel>
                        <sources/>
                        <weaveDirectories>
                            <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
                        </weaveDirectories>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
hanusto commented 8 years ago

For me in aspectj plugin and none in compiler plugin fix this error.

snicoll commented 8 years ago

@hanusto this issue is closed. This is a build setup issue and not related to Spring Boot. I am happy to improve the doc to help users setup stuff. I had a look to your project and I am confused as what the problem is. The meta-data is generated and the build works for me. If you're still having a question, please ask on stackoverflow.

markdathorne commented 6 years ago

Thank you, jmirc. I lost more than a couple of days over this and your params got my build working in Tomcat again! Muchas gracias, buddy.

t-beckmann commented 6 years ago

The root cause is an Eclipse Java Compiler (EJC) incompatibility, the AspectJ Compiler (AJC) is based in it. I files a bug report and suggested an easy fix at https://bugs.eclipse.org/bugs/show_bug.cgi?id=530665.