简体   繁体   English

如何将 arguments 传递给 maven 中的 annotationProcessor

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

for example例如

use kotlin-kapt使用 kotlin-kapt

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

or use annotationProcessor或使用 annotationProcessor

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

When I use Maven and rebuild当我使用 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>                                                                              

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看了Maven-compiler-plugin和KAPT的官方文档,还是没有找到答案

https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#compilerArgument 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 https://www.kotlincn.net/docs/reference/kapt.html#%E5%9C%A8-maven-%E4%B8%AD%E4%BD%BF%E7%94%A8

Have you tried adding them to under the maven plugin section?您是否尝试将它们添加到 maven 插件部分下?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使AnnotationProcessor测试带注释类型的*子类型*? - How do I make an AnnotationProcessor test *subtypes* of the annotated type? 如何将 arguments 传递给 KeyBinding 中的 AbstractAction? - How do I pass an arguments to an AbstractAction in a KeyBinding? 如何将参数传递给/重写ActionPerformed() - How do I pass arguments to/override ActionPerformed() 如何在RequestParams中传递int参数? - How do I pass int arguments in RequestParams? 如何在不破坏Maven发布插件的情况下传递javac多个命令行参数,其中一些包括冒号? - How do I pass javac multiple command-line arguments, some of which include colon, without breaking Maven release plugin? 如何在PowerShell脚本中将参数传递给命令? - How do I pass arguments to a command inside a PowerShell script? 我如何在Java中为Fitnesse Fixture传递程序参数? - how do i pass program arguments in java for my Fitnesse Fixture? 如何在 intelliJ IDE 中将系统属性传递给 Maven 测试 - How do I pass a system property to Maven test in intelliJ IDE 如何将参数传递给Java检测代理? - How do I pass arguments to a Java instrumentation agent? 如何将-Xlint:deprecation或-Xlint:unchecked传递给Maven? - How do I pass -Xlint:deprecation or -Xlint:unchecked to Maven?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM