简体   繁体   English

IntelliJ IDEA中的注释处理器编译

[英]Annotation Processor compilation in IntelliJ IDEA

I'm using the latest version of IntelliJ IDEA (13.1.4) and I'm developing my own custom annotation. 我正在使用最新版本的IntelliJ IDEA(13.1.4),我正在开发自己的自定义注释。

I currently have two modules on my project 我目前在我的项目中有两个模块

  • MyOwnCustomAnnotationProcessor (here I have the actual processor) MyOwnCustomAnnotationProcessor(这里我有实际的处理器)
  • MyOwnCustomAnnotationProcessorTest (this I basically have a couple classes annotated to see if it's all generating fine) MyOwnCustomAnnotationProcessorTest(这个我基本上有几个类注释,看它是否都生成正常)

I was working in Eclipse but I'm trying to migrate ot IntelliJ because I can't stand Eclipse. 我在Eclipse工作,但我正在尝试迁移IntelliJ,因为我无法忍受Eclipse。 I managed to make it kinda-of work in Eclipse by having an Ant build generating the .jar file of the main project and the Test classes would use this .jar. 我设法通过让Ant构建生成主项目的.jar文件并且Test类将使用此.jar来使它在Eclipse中有点工作。

But I can't make it work on IntelliJ. 但是我不能让它在IntelliJ上工作。

In Settings -> Compiler -> Annotation Processor I have a new profile, the test project is inside this profile, the profile is like: Settings -> Compiler -> Annotation Processor我有一个新的配置文件,测试项目在此配置文件中,配置文件如下:

注释处理器屏幕

I've also tried changing the Processor Path to the output folder (where there're classes n META-INF) but no luck. 我也尝试将Processor Path更改为输出文件夹(其中有类META-INF),但没有运气。 The generated folder is being created by the IDE, but it's not finding any processors. generated文件夹由IDE创建,但它找不到任何处理器。

Any tip on how to proceed here? 关于如何在这里进行的任何提示?

I ended up finding how to do it, if anyone is interested: 如果有人有兴趣,我最终找到了如何做到这一点:

  • In Project Structure menu add an artifact to the main project (the annotation processor project). 在“ Project Structure菜单中,将artifact添加到主项目(注释处理器项目)。 This artifact exports a .jar file with the annotation processor. 此工件使用注释处理器导出.jar文件。 Make sure to enable Build on Make , that way a new .jar will be generated every time you ask to Rebuild Project 确保启用Build on Make ,这样每次您要求Rebuild Project时都会生成一个新的.jar
  • In Settings - > Compiler -> Annotation Processor Enable annotation processing, check Processor Path and put the path of the exported .jar file. Settings - > Compiler -> Annotation Processor启用注释处理,检查Processor Path并放置导出的.jar文件的路径。 Make sure to put the processor. 确保放置处理器。

and that should be all. 这应该是全部。 Now everytime rebuilt project is clicked a new jar is generated and the second project will be re-generated with that new jar. 现在,每次单击rebuilt project都会生成一个新jar,并使用该新jar重新生成第二个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM