簡體   English   中英

如何將 arguments 傳遞給 maven 中的 annotationProcessor

[英]How do I pass arguments to the annotationProcessor in maven

例如

使用 kotlin-kapt

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

或使用 annotationProcessor

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

當我使用 Maven 並重建時

<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>                                                                              

出現以下錯誤

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

看了Maven-compiler-plugin和KAPT的官方文檔,還是沒有找到答案

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

您是否嘗試將它們添加到 maven 插件部分下?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM