How do I pass arguments to the annotationProcessor in maven

Viewed 565

for example

use kotlin-kapt

kapt {
    arguments {
        arg("key", "value")
    }
}

or use annotationProcessor

defaultConfig {
   javaCompileOptions {
      annotationProcessorOptions {
         arguments = [ key : 'value' ]
      }
   }
}

When I use Maven and rebuild

<plugin>                                                                               
    <groupId>org.apache.maven.plugins</groupId>                                        
    <artifactId>maven-compiler-plugin</artifactId>                                     
    <version>3.6.1</version>                                                           
    <configuration>                                                                    
        <source>1.8</source>                                                           
        <target>1.8</target>                                                           
        <annotationProcessorPaths>                                                     
            <path>                                                                     
                <groupId>org.greenrobot</groupId>                                      
                <artifactId>eventbus-annotation-processor</artifactId>                 
                <version>3.2.0</version>                                               
            </path>                                                                    
        </annotationProcessorPaths>                                                    
                                                                                       
        <annotationProcessors>                                                         
            <annotationProcessor>                                                      
                org.greenrobot.eventbus.annotationprocessor.EventBusAnnotationProcessor
            </annotationProcessor>                                                     
        </annotationProcessors>                                                        
                                                                                       
        <fork>true</fork>                                                              
        <compilerArgs>                                                                 
            <compilerArg>-eventBusIndex=com.example.test.MyEventBusIndex</compilerArg> 
        </compilerArgs>                                                                
    </configuration>                                                                   
</plugin>                                                                              

The following error occurs

Error:java: Invalid mark: -eventBusIndex=com.example.test.MyEventBusIndex

After reading the official documents of Maven-compiler-plugin and KAPT, I still haven't found the answer

https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#compilerArgument

https://www.kotlincn.net/docs/reference/kapt.html#%E5%9C%A8-maven-%E4%B8%AD%E4%BD%BF%E7%94%A8

1 Answers

Have you tried adding them to under the maven plugin section?

<configuration>
    ...
    <compilerArgs>
        <compilerArg>-Key=value</compilerArg>
    </compilerArgs>
<configuration>
Related