英文:
Testing of annotation processor in java
问题
我正在开发一个注解处理器,现在我正在进行测试的下一步:
- 将更改提交并推送到 GitHub
- 使用 JitPack 构建和发布处理器
- 在 Idea 中刷新 Gradle。我测试项目中的 build.gradle 内容如下:
repositories {
maven { url 'https://jitpack.io' }
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compileOnly 'com.github.hohserg1:MyAnnotationProcessor:main-SNAPSHOT'
}
- 尝试构建
这非常糟糕。如何简化为"点击运行按钮"?
英文:
I am developing an annotation processor and now I doing next steps for testing:
- commit and push changes to github
- use jitpack for build and publish processor
- refresh gradle in Idea. build.gradle in my test project:
repositories {
maven { url 'https://jitpack.io' }
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compileOnly 'com.github.hohserg1:MyAnnotationProcessor:main-SNAPSHOT'
}
- try to build
It very terrible. How to reduce it to "press run button"?
答案1
得分: 1
你需要将处理器、注解和应用程序分别放在不同的模块中,每个模块都是一个不同的依赖项。你这样做是为了避免处理器和应用程序之间出现循环依赖,并且可以帮助你避免将处理器类包含在应用程序构件中。
此外,注意在开发注解处理器时,你不会测试处理器本身,而是测试从该处理器生成的代码,如果生成的代码能够正常工作,那么处理器也会按预期工作。
英文:
You would need your processor, your annotation, and the application to be each in a different module is a different dependency, you do this to avoid cyclic dependency between the processor and the application, and also help you to avoid including the processor classes in your application artifacts.
also, note that when you develop an annotation processor you don't test the processor itself but you test the code generated from that processor if the generated code works then the processor is also working as expected.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论