This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I process compile time annotations from a Mojo

 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have couple of modules that have the following

a) A bunch of XML files
b) A custom compile time Annotation on several java files
c) A bunch of other resources that contain snippets of the final artifact.

All these need to be processed to create a single artifact. So, right now what we have done is
a) Implement a Mojo that converts the XML to a snippet of the artifact
b) Implement an Annotation processor that generates snippets of the artifact by processing the compile time annotation
c) Implement another mojo that merges the 3 snippets together into one artifact

We have to run this process twice because there are minor differrences in the artifact that is used for unit testing vs the artifact used for production

Everything works fine, but the problem is my pom.xml is very big. I have 2 of my own plugins and maven processor plugin. Both of my plugins have 2 executions, one for production, one for test. Also, the final artifact is being created by 3 seperate plugins, fixing problems is kind of a pain

I wanted to merge all 3 functions into one MOJO. I can merge my 2 Mojos easily, but how do I process compile time annotations from my Mojo?. Is there a code sample available somewhere?
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Annotation processor is just some Java code, right? Couldn't you invoke that code directly from your mojo? If nothing else, you could always directly call the main() method of the main class. Though most likely that just does some processing of the arguments and then calls another class - it is that class that you really want to call.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic