【问题标题】:Resolving warning for Micronaut and Gradle 5 "Detecting annotation processors on the compile classpath is deprecated" warning解决 Micronaut 和 Gradle 5“检测编译类路径上的注释处理器已弃用”警告的警告
【发布时间】:2018-08-06 05:43:47
【问题描述】:

我正在尝试从 Gradle 解决以下警告。它仅在我调用测试代码时发生。主要的 Java(仅)运行和构建任务工作正常。

测试代码在 Groovy 中。似乎 Groovy 与 Gradle 和 Micronaut 结合在几周前解决了该消息但顽固地坚持在 testtestCompile 相关任务上的项目中提出了此消息。

> Task :plumbing:compileTestGroovy
The following annotation processors were detected on the compile classpath: 
'io.micronaut.annotation.processing.TypeElementVisitorProcessor' and     'io.micronaut.annotation.processing.PackageConfigurationInjectProcessor' and
'io.micronaut.annotation.processing.BeanDefinitionInjectProcessor'.
 Detecting annotation processors on the compile classpath is
 deprecated and Gradle 5.0 will ignore them. Please add them
 to the annotation processor path instead. If you did not 
intend to use annotation processors, you can use the 
'-proc:none' compiler argument to ignore them.

从 Micronaut 开始,我通过反复试验发现使用 Lombok 的说明到目前为止,运行 Groovy 测试的唯一方法是使用 build.gradle 文件中的以下配方。 Micronaut 配方指定将 Lombok 放在 Micronaut 之前。这对 Java 构建有效。

为了让 Groovy 代码编译然后执行,我(似乎)需要这样编写我的依赖项:

configurations {
    annotationProcessor
}

dependencies
{
    compileOnly (
        dep_lombok                  //  Must come first
    )

    annotationProcessor (
        dep_lombokAtnProc,          //  Must come first
        dep_micronautAtnProc
    )

    compileOnly (
        dep_micronaut              //  Must follow annotationProcessor 
    )

    implementation (
        project( ':base'),
    )

    testImplementation (
        project( ':TestingSupport')
    )

    testImplementation (
        dep_micronaut,
        dep_commonsConfig
    )
}
  • 依赖关系dep_XXX 只是字符串。
  • AtnProc...”标签用于专门标识注解处理器(即使是同一坐标)。

如果compileOnly ( dep micronaut ) 子句必须使用Groovy 构建处理@Inject 之类的内容。还有……

  • 它必须按照显示的顺序,在annotationProcessor(..) 子句之后。

尽管此时 Groovy 文件中没有注释。

使用上述构建信息,Groovy 规范可以正常运行和工作。但是我仍然收到Deprecated ... 警告。

如果没有compileOnly( Micronaut ) 短语,我会收到编译错误并且没有任何运行。 testCompileOnlygroovyCompileOnlytestAnnotationProcessor 什么都不做。

谁知道在使用 Micronaut 时如何使用 Gradle 构建和运行 Groovy 测试?测试与龙目岛罚款共存。

缺少的东西有@Inject@Singleton等。

期待建议和想法。

【问题讨论】:

    标签: gradle groovy deprecation-warning micronaut


    【解决方案1】:

    添加annotationProcessor 配置后,主模块的警告已解决,但测试模块继续存在,这让我相信注释处理器正在您的测试代码中使用。

    kapt Kotlin annotation processor 插件类似,我认为您需要为您的测试模块配置注释处理器,testAnnocationProcessor 如下:

        testAnnotationProcessor (
            dep_lombokAtnProc,
            dep_micronautAtnProc
        )
    

    【讨论】:

    • 谢谢,这是一个跟进的想法。我相信test“继承”了编译和运行时构建规范中的任何内容。如果这行得通,那么这将表明这毕竟不是这样。嗯?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 2017-03-12
    • 2017-03-06
    相关资源
    最近更新 更多