Bad service configuration file, or exception thrown while constructing Processor object

后端 未结 4 1850
难免孤独
难免孤独 2021-02-20 06:23

I am writing a simple custom annotation in Java and running into a problem with it. Here is the main parts of my code.

LogMeCustomAnnotation.java

4条回答
  •  借酒劲吻你
    2021-02-20 06:46

    The default maven lifecycle runs javac with javax.annotation.processing.Processor file as a part of classpath. This cause compiler to expect a compiled instance of annotation processors listed in the files. But LogMeCustomAnnotationProcessor is not compiled at that moment so compiler raises "Bad service configuration file ..." error. See bug report.

    To solve this issue maven compilation phase can be separated to compile annotation processor at the first place and then compile whole project.

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.5.1
                
                    1.8
                    1.8
                
                
                    
                        default-compile
                        
                            -proc:none
                            
                                fun/n/learn/annotation/LogMeCustomAnnotationProcessor.java
                                
                            
                        
                    
                    
                        compile-project
                        compile
                        
                            compile
                        
                    
                
            
        
    
    

    default-compile execution compiles LogMeCustomAnnotationProcessor with disabled annotation processing in order to have successful compilation.
    compile-project compiles whole project with annotaton processing.

提交回复
热议问题