Gradle插件与AutoValue和FreeBuilder混淆/冲突

问题描述 投票:1回答:1

我正在试验Gradle / IntelliJ和各种Java构建器/容器。但是,我无法在同一项目中配置org.inferred.FreeBuilder和com.google.auto.value.AutoValue。

使用下面的build.gradle文件,我能够成功编译一个使用AutoValue的类(来自AutoValue documentation的动物示例)。

但是,只要我取消注释“id'org.inferred.processors”和“processor'org.inferred:freebuilder:1.14.6'”我就得到了

:processorPath \ main \ java \ example \ com \ Animal.java:12:error:找不到符号返回new AutoValue_Animal(name,numberOfLegs); ^符号:类AutoValue_Animal位置:类Animal 1错误:compileJava FAILED

plugins {
    id 'java'
    id 'idea'
    id 'net.ltgt.apt-idea'  version '0.13'
    // id 'org.inferred.processors' version '1.2.15'
}

version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.google.auto.value:auto-value:1.5.1'
    apt 'com.google.auto.value:auto-value:1.5.1'

    //processor 'org.inferred:freebuilder:1.14.6'
}

jar {
    from {
        (configurations.runtime).collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    manifest {
        attributes 'Main-Class': 'example.com.Main'
    }
}

idea {
    project {
        // experimental: whether annotation processing will be configured in the IDE; only actually used with the 'idea' task.
        configureAnnotationProcessing = true
    }
    module {
        apt {
            // whether generated sources dirs are added as generated sources root
            addGeneratedSourcesDirs = true
            // whether the apt and testApt dependencies are added as module dependencies
            addAptDependencies = true

            // The following are mostly internal details; you shouldn't ever need to configure them.
            // whether the compileOnly and testCompileOnly dependencies are added as module dependencies
            addCompileOnlyDependencies = false // defaults to true in Gradle < 2.12
            // the dependency scope used for apt and/or compileOnly dependencies (when enabled above)
            mainDependenciesScope = "PROVIDED" // defaults to "COMPILE" in Gradle < 3.4, or when using the Gradle integration in IntelliJ IDEA
        }
    }
}

我试图从这些来源中提取信息:

java gradle gradle-plugin auto-value freebuilder
1个回答
1
投票

您可以在项目中同时使用gradle依赖项,但不能同时使用它们的gradle插件。你也不应该这样做。

您只需要一个gradle插件用于注释处理器支持(其中任何一个),然后所有bean处理器依赖项都应该工作。

© www.soinside.com 2019 - 2024. All rights reserved.