【问题标题】:How do I pass arguments to the annotationProcessor in maven如何将参数传递给 Maven 中的 annotationProcessor
【发布时间】:2020-11-06 07:26:36
【问题描述】:

例如

使用 kotlin-kapt

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

或者使用注解处理器

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

【问题讨论】:

  • 考虑到您发布的两个示例,问题有点不清楚。您是在问哪种方式更好还是它们不起作用?

标签: java android maven gradle annotations


【解决方案1】:

您是否尝试将它们添加到 maven 插件部分下?

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

【讨论】:

  • 我试过了,但是重建的时候出现如下错误:Error:java: Invalid mark: -eventBusIndex=com.example.test.MyEventBusIndex
猜你喜欢
  • 1970-01-01
  • 2023-03-10
  • 2018-08-12
  • 2019-09-29
  • 2016-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-06
相关资源
最近更新 更多