将注释处理器与Gradle集成 [英] Integrating annotation processors with Gradle

查看:139
本文介绍了将注释处理器与Gradle集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一些注释处理器。我发现了这篇博文,其中提到了如何在一般设置和Eclipse中完成。

然而,我正在使用IntelliJ IDEA和Gradle,并且如果有更好的(比较简单,乏味)方法来做到这一点,就会喜欢它。我在找什么:


  1. 我应该能够在同一个项目中编写注释处理器和将要使用它们的代码,并且Gradle应该将处理器添加到类路径中,并在approrpiate阶段使用javac调用它们。

  2. 如果上述操作不可行并且我必须创建两个单独的项目,那么在至少应该可以将它们保留在同一个git存储库中。 Gradle应该能够无缝地处理构建。

    如果两者都不可能,我必须创建两个独立的git存储库,那么至少Gradle应该处理无需进一步的手动干预即可无缝链接博客文章。

我的git和Gradle技能都是初级水平。我将不胜感激这项任务的任何帮助。谢谢。

解决方案

另一个解决方案(在我看来更清洁)可能会有两个子项目,然后简单地将包含注释处理程序的注释处理程序与主程序库相关联。因此,在项目的根目录中为您的子项目提供了两个目录: core annotation-processors ,您需要还有一个 settings.gradle 文件,其中包含以下内容:

  include' core'
include'annotation-processors'

然后在gradle文件中为核心项目:

 依赖关系{
编译项目(':annotation-processors')
}

应该这样做,您不必处理自定义编译任务及其类路径。


I need to write some annotation processors. I found this blog post which mentions how that can be done in a general setting and with Eclipse.

However I am using IntelliJ IDEA and Gradle, and woud like it if there were a better (as in, less tedious) approach to do it. What I am looking for:

  1. I should be able to write both annotation processors and the code that will be consuming them in the same project and Gradle should handle adding the processors to class path and invoking them with javac at approrpiate stage.
    OR
  2. If the above is not possible and I have to create two separate projects, then at least it should be possible to keep them in the same git repository. Gradle should handle the build seamlessly.
    OR
  3. If neither is possible and I have to create two separate git repositories, then at the very least, Gradle should handle the things mentioned in the linked blog post seamlessly without further manual intervention.

My git and Gradle skills are beginner level. I would appreciate any help with this task. Thank you.

解决方案

Another solution (in my opinion cleaner) could be to have two subprojects and then simply make the one that contains annotation processors a dependency of the main one. So given two directories with your subprojects: core and annotation-processors in the root of your project, you would need to also have a settings.gradle file with the following:

include 'core'
include 'annotation-processors'

And then in the gradle file for the core project:

dependencies {
    compile project(':annotation-processors')
}

That should do it and you won't have to deal with custom compile tasks and their classpaths.

这篇关于将注释处理器与Gradle集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆