【问题标题】:Annotation processing with gradle nothing in factorypath on eclipseeclipse上的工厂路径中没有gradle的注释处理
【发布时间】:2018-09-02 08:54:52
【问题描述】:

我正在从 maven 切换到 gradle。

这是我以前在 pom.xml 中的内容

        <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgument>-proc:none</compilerArgument>
                </configuration>
        </plugin>
        <plugin>
            <groupId>org.bsc.maven</groupId>
            <artifactId>maven-processor-plugin</artifactId>
            <version>3.3.1</version>
            <executions>
                <execution>
                    <id>process</id>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <phase>generate-sources</phase>
                </execution>
                <execution>
                    <id>process-test</id>
                    <goals>
                        <goal>process-test</goal>
                    </goals>
                    <phase>generate-test-sources</phase>
                    <configuration>
                        <sourceDirectory>./test</sourceDirectory>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>rockpalm.it</groupId>
                    <artifactId>ic2-annotation-processor</artifactId>
                    <version>1.2.1-SNAPSHOT</version>
                </dependency>
            </dependencies>
        </plugin>

我的 build.gradle 看起来像:

plugins {
  id "net.ltgt.apt" version "0.15"
  id 'net.ltgt.apt-eclipse' version '0.15' 
}
dependencies {
    annotationProcessor "rockpalm.it:ic2-annotation-processor:1.2.1-SNAPSHOT"
}
ext { 
    eclipseAptFolder = '.apt_generated'
    eclipseSettingsDir = file('.settings')
}

eclipse {
    jdt.file.withProperties { 
        it['org.eclipse.jdt.core.compiler.processAnnotations'] = 'enabled'
    }
}

tasks.eclipseJdt {
    doFirst {
        def aptPrefs = file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs")
        aptPrefs.parentFile.mkdirs()

        aptPrefs.text = """\
    eclipse.preferences.version=1
    org.eclipse.jdt.apt.aptEnabled=true
    org.eclipse.jdt.apt.genSrcDir=${eclipseAptFolder}
    org.eclipse.jdt.apt.reconcileEnabled=true
    """.stripIndent()

        file('.factorypath').withWriter {
            new groovy.xml.MarkupBuilder(it).'factorypath' {
                project.configurations.annotationProcessor.each { dep->
                    factorypathentry(
                        kind:'EXTJAR',
                        id:dep.absolutePath,
                        enabled:true,
                        runInBatchMode:false
                    )
                }
            }
        }
    }
}

但是当我使用 Gradle > Refresh gradle 项目时,它没有使用我的注释处理器配置 eclipse 的 .factorypath,它启用它但没有在处理器列表上设置实际处理器。

当我运行 gradle build 时,我实际上可以在 build/generated/source/apt/main/...my packages/classes 中看到我生成的代码,但由于它在 eclipse 中没有启用,所以我在 .apt_generated 文件夹中没有任何内容。

编辑 我得到了 gradle 以使用 build.gradle 的 tasks.eclipseJdt 部分正确构建工厂路径,但 eclipse 似乎仍然没有在 .apt_generated 构建任何东西。如何调试 eclipse gradle build 以查看发生了什么?

感谢任何帮助,谢谢

【问题讨论】:

  • 我也有同样的问题。执行gradle eclipse后——在eclipse中激活“注解处理”,“工厂路径”也设置正确。 Eclipse 不生成任何东西。 gradle build 正在控制台上运行。你找到工作了吗?

标签: gradle annotation-processing


【解决方案1】:

您通常不需要插件示例中的 eclipse 配置闭包,只需使用:

plugins {
    id 'net.ltgt.apt' version '0.15'
    id 'net.ltgt.apt-eclipse' version '0.15' 
}

dependencies {
    annotationProcessor 'rockpalm.it:ic2-annotation-processor:1.2.1-SNAPSHOT'
}

执行gradle eclipse 设置工厂路径并在Eclipse中刷新项目。

【讨论】:

  • 它仍然没有在 .apt_generated 编译任何东西
  • 出厂路径文件是否存在?您确定您的注释处理器有效吗?依赖是否正确?
  • 我确定它可以工作,因为它适用于 maven,并且适用于 gradlew 构建,.factory 存在,但仅包含 &lt;factorypathentry kind="PLUGIN" id="org.eclipse.jst.ws.annotations.core" enabled="false" runInBatchMode="false"/&gt;,因此依赖项是正确的,因为它适用于 maven
猜你喜欢
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
  • 2014-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-15
  • 1970-01-01
相关资源
最近更新 更多