Hi,
I was wondering if there is a way to configure the maven apt
plugin so that it does not generate query types that match a
configurable list of packages and/or classes?
I have multiple
projects that each import a project A, the Entities in A are generated
for every project importing A. This leads to duplicate classes in the
overall build.
If this is currently not possible, could it be
added? E.g. by adding <excludePackages> and/or
<excludeClasses> to the configuration of the plugin?
cheers
Lars
timowestWould it be possible to generate the Q-types for project A in the build of project A?
That's another way to solve the problem.
laazThis is what is done at the moment. The problem is that projects X which
depend on project A generate the Q classes for project A again. I
assume this is because the Entities of project A are in the classpath of
the projects X?
timowestHm, I will try to replicate this locally. In your setup they shouldn't be regenerated.
Are the Q-types of project A also in the classpath of project X?
laazBasically we have project X which has a maven dependency on project A.
Both project contain javax.persistence.Entity annotated classes. The
maven plugin running in project X picks up the Entity classes in both
projects X and A. But project A already contains its Q classes.
Btw,
I had a quick look into writing a patch for the maven plugin to exclude
packages and/or classes. But how can I pass configuration parameters
from the Maven Mojo to the (annotation) processor?
timowestvia the options configuration parameter :
/**
* @parameter
*/
protected Map<String,String> options;
laazMight be a dumb question ... but in which class is this parameter?
timowestSorry, my fault. I should have been more specific. The sources for maven-apt-plugin are here :
https://source.mysema.com/svn/mysema/projects/maven/maven-apt-plugin/trunk/The class you are interested in is com.mysema.maven.apt.AbstractProcessorMojo
On the Querydsl side, take a look at querydsl-apt and com.mysema.query.apt.DefaultConfiguration
laazNo worries, I actually didn't check out the correct project for the maven plugin. Did you get a chance to replicate the issue?
I
have an (untested) patch to exclude packages and/or classes. Should I
create a new bug/issue for this or is there another way to send it to
you, only if you're interested of course. ;)
The configuration would look like below.
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.hibernate.HibernateAnnotationProcessor</processor>
<options>
<querydsl.excludedPackages>com.excluded.packagename</querydsl.excludedPackages>
<querydsl.excludedClasses>com.excluded.ClassName,com.another.ExcludedClass</querydsl.excludedClasses>
</options>
</configuration>
P.S: Sry, for the bad formatting.
timowestI have not yet been able to replicate the issue. You could file a bug report and attach the patch.
laazOk, did that. See
https://bugs.launchpad.net/querydsl/+bug/751557 .
I'm not 100% certain if the check in the Processor class is the right place to do this.
timowestI just added the querydsl.excludedPackages and querydsl.excludedClasses
options. I will try to replicate the issue with multiple modules later
today.
laazThanks for that!
One more question ... when are you planning on
releasing the next beta or final version? Or is there a Maven repository
with the current snapshot release? We tried adding the one linked to on
the querydsl homepage but this cannot be indexed by Nexus.
Cheers,
Lars
timowestI will do a new beta-release later today
Sorry, I had to postpone the release to tomorrow, but I have been able to reproduce the original problem.
I will see if I can also create a fix for it, but it is definitely more difficult than the excludedPackages/Classes fix.
laazNo worries,
thanks for looking into it.
timowestI just got the release made : 2.2.0-beta3
laazGreat!
Just wondering when this release will be available in Maven central?
timowestProbably tomorrow, it gets synced automatically after some while.
laazOk, thanks.
You mentioned that the problem is actually another one? Do you already know what it is?
timowestThe problem is that is quite difficult to identify already generated Q-types from external modules in APT.
laazMaybe a Maven ArtifactResolver could help when using the Maven plugin? Not sure tough, unfortunately I'm not a Maven expert.
timowestThe APT processor is independent of Maven, it is actually more of a plugin to Javac, so I can't use any Maven project metadata.
The maven-apt-plugin is just wrapper plugin to make using APT via Maven a bit easier.
laazHi Timo,
just a wondering if there is an issue on launchpad for this so I can track it?
Unfortunately the problem is currently preventing us from using querydsl in our application.
Thanks heaps
Lars
timowestYou should be able to use Querydsl with the excludedPackages & excludedClasses APT options.
They are in the 2.2.0-beta3 release, which is now available in the central Maven repos :
http://repo2.maven.org/maven2/com/mysema/querydsl/querydsl-root/2.2.0-beta3/laazYup, tried that. But it looks like my patch doesn't really work. The
query java files for types in the parent project are still generated.
timowestCould you post the relevant maven-apt-plugin configuration here?
Here is a configuration that works :
<configuration>
<processor>com.mysema.query.apt.QuerydslAnnotationProcessor</processor>
<options>
<querydsl.excludedPackages>com.mysema.query.domain.rel</querydsl.excludedPackages>
</options>
</configuration>
Here is an issue for the core problem :
https://bugs.launchpad.net/querydsl/+bug/754503laazUnfortunately this doesn't seem to work. The Q source for the parent
project still get generated. I guess my patch didn't really do what is
was supposed to do. Maybe I picked the wrong spot for the check whether a
type is excluded or not?
timowestCould you provide some more info? Which Querydsl version did you use? Can you provide the Maven plugin configuration snippet?
laazThe querydsl version is the 2.2.0-beta3 version. The plugin config is:
Sry, pressed the reply button too early.
Config is as follows:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.hibernate.HibernateAnnotationProcessor</processor>
<options>
<querydsl.excludedPackages>com.excluded</querydsl.excludedPackages>
</options>
</configuration>
</execution>
</executions>
</plugin>
timowest
Lars, I just sent you an example project which demonstrates the usage.
Your configuration looks ok, I don't know yet, what went wrong.
Try the example and tune it to reflect your setup.