Any way to strip off some annotations by maven? - maven

I wonder if there a way to strip off some annotations when 'maven build' ?
For convenience reason , I annotate some 3rd party's annotation into my POJO , such as javax.persistence.* , org.hibernate.annotations.* , org.apache.lucene.analysis.* ... blah...blah.
It works well when I bundle them together and deploy to a JavaEE/Spring server/container.
But when developing Android , I want to make the most reuse of my code/POJOs. I want to directly import foobar.core.User instead of creating another foobar.android.User without 3rd party annotations. That is , I don't want the jar dependent on other spring/hibernate artifacts.
So , is there any way to strip off some annotations when running 'maven build' ? I just need to strip off 'some' 3rd party annotations , and keep custom core annotations.
So that I can build foobar-core.jar and foobar-core-stripped.jar respectively or simultaneously.

Trying to do exactly the same thing. I found an ant task that can strip annotations from compiled classes.
http://sourceforge.net/projects/purgeannorefs/
The maven ant plugin can then be used to call the ant task as part of your maven build.
I know it's a bit of a workaround. But better than having to maintain 2 copies of the pojo objects.

If you can't find a non-maven tool that does the job, you aren't going to find a maven plugin. Mmake stub copies of the annotation classes put them in a jar, and add them into the classpath for Android.

You can use the maven-antrun-plugin to do a find and replace on all annotations... I did this at the following answer to comment out all #XmlAttribute annotations:
https://stackoverflow.com/a/10036841/342745
Kind of hacky, but it worked for me.

Related

Gathering javadocs from multimodule maven project

In a large maven multimodule context,
how can I gather javadoc-comments programmatically for a specific set of classes (e.g. all classes implementing some interface) or modules ?
I have tried a stupid doclet and looked at QDox, but neither seems to do the job well.
Actually I think this should be simple if done correctly.
Specifically, I do not know how to do this in a maven-build: How can I depend on and use the src-jars?
This should be possible with QDox, as long as you have the sources. QDox-2.x can also read source-files from jars, which can be generated by the maven-source-plugin.

Maven Plugin: Use Classes out of the Plugin

when i use a plugin, is there a way to use classes out of the plugin?
I created a maven-plugin and i want the plugin to be used when you
have a class inheriting from a specific interface. The interface
is inside my maven-plugin.
Now i create a maven-projekt using my maven-plugin.
How can i use my interface out of the maven-plugin?
Well, projects can always have a dependency on a plugin. I mean -- they're also regular artifacts.
If I were you, I would extract the common code which could be used outside the plugin, into a separate module (artifact). This way both the plugin and the projects which need to depend on it will be neat. Even if it's for one class.

Maven, NetBeans Platform, Wrapper Modules and Annotation Processors on dependencies

I have a Maven NetBeans platform application. One of its modules is a wrapper to a java project (jar) that exposes some services to the Lookup. In the wrapped project I use the maven-processor-plugin to process the annotations so everything gets registered in the Lookup. I’m unable to see the exposed classes on the wrapped module. I tried running the maven-processor-plugin but it is skipped since there are no source files in the wrapped module. Even if there were it wouldn’t fix the problem.
You can get the code here, in the Marauroa Server Manager project, Module: jWrestling Wrapper.
The code for the wrapped module can be found here. Annotated classes within the modules work fine.
Is there a way to execute the annotation processors on the dependencies of a project? Am I missing something obvious?
the wrapped jar project cannot contain nb.org annotations. these generate META_INF/generated-layer.xml file that is only read from a MODULE jar, not the wrapped non-module jar
the binary dependency contains some netbeans-originating annotations? and you want to process it through the maven plugin? that won't work. Most if not all netbeans annotations are compile-time only, meaning that they are processed at compile time and not retained in the bytecode. so only su
Besides for Netbeans annotations (which are based on jdk 1.6 annotation processors, you don't need the processor plugin, compile plugin should be sufficient.

Make maven build fail created artifact contains certain classes

I have complex multi-pom setup that in the end will create an EAR package. Sometimes the dependencies are messed up and some unwanted dependencies like JUnit end up in the final EAR package.
Is there a way to make maven build fail if final artifact contains certain classes?
Maybe not failing but you can exclude some jar-files that you know you will never use.
The maven-ear-plugin has a tag to use when excluding files, look here.
Use the <packagingExcludes/> tag to exclude JUnit for example.
You could use the maven-enforcer-plugin with a custom rule that you probably would have to write yourself. I haven't searched, but I don't think that such a rule exists yet.

Use Local Maven Repository

How can I use jars that buildr loads by default into the local maven repo, rather than creating new (and repetitive) artifact tasks/dependencies?
For example, if were creating a scala or groovy application buildr would automatically download the scala or groovy jars respectively. Is it possible to include or merge these (default) jars into an application rather than creating a new artifact?
I think that is not possible or doable in a one step, easy way. I recommend you talk with us on the dev list of Buildr and we can probably create an enhancement for that.
For each library you would like to depend on, you usual can grep the code to find where we define the default jar we depend on.
For the example you mention, here are the default method to retrieve the default jars:
For Groovy: Buildr::Groovy::Groovyc.dependencies
For Scala: Buildr::Scala::Scalac.dependencies
I hope that helps.

Resources