在使用Groovy、IntelliJ和Gradle的项目中重新运行SpringBoot配置注解处理器

3
我正在使用IntelliJ 15.0.6、SpringBoot 1.4.3.RELEASE、Gradle 2.14和Groovy 2.3.11进行编程。
我从IntelliJ得到以下信息:

enter image description here

我尝试按照StackOverFlow官方文档JavaCodeGeeks的指导进行操作,但均未成功。
这是我的配置文件:
@Configuration
@ConfigurationProperties(prefix = "configuracoes")
class GeralConfiguration {
    def proxyEndereco
    def proxyPorta
}

以下是我的application.yaml文件中相关部分:

configuracoes:
    proxyEndereco: http://fake.com
    proxyPorta: 8080

如果我从配置文件中删除@ConfigurationProperties,消息将消失。
这是我的build.gradle文件:
buildscript {
    repositories {
        mavenLocal()
        maven {url('http://repo.spring.io/plugins-release')}
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE")
        classpath('org.springframework.build.gradle:propdeps-plugin:0.0.7')
    }
}

apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'propdeps'
apply plugin: 'propdeps-idea'
sourceCompatibility = 1.7

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter")
    compile("org.springframework.boot:spring-boot-devtools")
    optional("org.springframework.boot:spring-boot-configuration-processor")
    compile('org.codehaus.groovy:groovy-all:2.3.11')
    compile('com.machinepublishers:jbrowserdriver:0.17.3')
    compile("org.im4java:im4java:1.4.0")

    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile("org.spockframework:spock-core:1.1-groovy-2.4-rc-3")
}

compileJava.dependsOn(processResources)
compileGroovy.dependsOn(processResources)

有什么想法以及我如何解决这个问题吗?
2个回答

2

很遗憾,注解处理器不支持Groovy。您可能希望报告IJ不应该在Groovy代码中显示此警告。


1
为什么在同一个项目中的Java类中不起作用呢?我知道Java类由Gradle的“compileJava”任务处理,而Groovy类由“compileGroovy”处理。我错了吗? - Sidney de Moraes
它应该与同一项目中的Java类一起工作。如果不看它,我无法告诉你原因。 - Stephane Nicoll

2

@Stephane 帮我找到了答案。

确实,Groovy 不支持注解处理器。但是我也没能让它在 src/main/java 中工作。

我发现 build 文件夹中的 classes 子文件夹被 IntelliJ 标记为 excluded(我不知道原因)。

当我一步步修复问题时,我从未成功过。当我一次性地完成所有修复并将 classes 子文件夹标记为 NOT excluded 时,所有东西都正常工作了(尽管 IntelliJ 仍然显示错误消息)。

感谢 @Stephane 的帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接