QueryDsl - How to create Q classes with maven? - spring

I have web project spring mvc with spring data
here is example :
https://github.com/prilia/SpringJpa-Quarydsl-Test/tree/master/JpaSpringQuarydsl
I checked a lot of pom.xml that I found in web to create a Q classes of entities, but no lack.
Please help me with creating Q classes with maven.

you need plugin, try this:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.4</version>
<executions>
<execution>
<id>process-common-model</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<sourceDirectory>${project.build.directory}/{yourSourceDir}</sourceDirectory>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>target/generated-sources/querydsl</outputDirectory>
<processors>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</processors>
<options>
<querydsl.entityAccessors>true</querydsl.entityAccessors>
<querydsl.createDefaultVariable>true</querydsl.createDefaultVariable>
<querydsl.packageSuffix>.qdsl</querydsl.packageSuffix>
</options>
</configuration>
</plugin>
I copied this from my project. just added it to your pom and have a try.
There are additional options in the code above, if you just wanna a simple one, focus on the querydsl reference

Related

How to generate java model classes without annotations using openapi-generator-maven-plugin/ swagger?

I want to generate java model classes from yaml file without annotations in generating classes.
How it is possible to generate? I tried multiple ways but not able to generate model classes without annotations. Always containing annotations in generating classes.
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/pesttore.yml</inputSpec>
<modelPackage>com.my.path.to.api</modelPackage>
<generatorName>java</generatorName>
<generateApis>false</generateApis>
<generateModels>true</generateModels>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<apisToGenerate>false</apisToGenerate>
<withXml>false</withXml>
<!--<library>resttemplate</library> -->
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<serializableModel>true</serializableModel>
<dateLibrary>java8</dateLibrary>
<annotationLibrary>none</annotationLibrary>
<serializationLibrary>jsonb</serializationLibrary>
<additionalModelTypeAnnotations>null</additionalModelTypeAnnotations>
<documentationProvider>none</documentationProvider>
<additional-properties>generateModelBuilders=true,useJackson=false,sortParamsByRequiredFlag=false,useJacksonJsonIgnoreUnknownProperties=false</additional-properties>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
This was added in version 5.4.0 in this PR. You'll need to update your plugin version.

How customize package-info.java generated by JAXB2

Which is the best way to customize a generated package-info with the annotation #XmlJavaTypeAdapter? My package info already has "#javax.xml.bind.annotation.XmlSchema" annotation.
I'm using Maven and Liferay 6.2.
My solution for the jaxb2-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>bla</id>
<phase>generate-resources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sources>
<source>${somevariable}/somexsd.xsd</source>
</sources>
<outputDirectory>src/main/generated-sources/jaxb/</outputDirectory>
<encoding>UTF-8</encoding>
<locale>en</locale>
<packageName>de.something.generated</packageName>
<noPackageLevelAnnotations>true</noPackageLevelAnnotations>
</configuration>
</execution>
</executions>
</plugin>
with "noPackageLevelAnnotations=true" there will be no generated package-info.java in your package "de.something.generated"
now you only have to add under your normal src/main/java the same package "de.something.generated" and place there your own package-info.java
just build and enjoy ;)

jaxb classes generated from the maven-jaxb2-plugin does not go under desired package

I am able to generate classes with maven-jaxb2-plugin.
Classes are generated as per below file structure
com.test.vo
org
tempuri
myobject.java
myobjectreponse.java
But I wish that classes are generated direct my expected package(com.test.vo).
I have set my plugins like below
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<extension>true</extension>
<schemaDirectory>src/main/resources/wsdl</schemaDirectory>
<packageName>com.test.vo</packageName>
<generateDirectory>com.test.vo</generateDirectory>
</configuration>
</execution>
</executions>
</plugin>
let me if anyone needs more information
If you replace
<packageName>com.test.vo</packageName>
with
<generatePackage>com.test.vo</generatePackage>
your generated classes will be placed under this Java package. Good luck!

how to define an additional source directory in maven-apt-plugin

We have some of our JPA entities generated in target/java directory during maven goal "generate". But not all of them are generated, as some of them are in our src/main/java directory. Is there any way to configure the plugin to specify more than one source directory?
I have tried with <additionalSourceRoots>target/java<additionalSourceRoots> but it does not work. I halve also tried to add target/java but then this is the only directory that is processed to the other JPA entities that are in the main code that are not generated are not processed.
I know I could try a workaround trying to copy the generated sources to another directory and putting there the other entities as well, but I am wondering if there is a "clean" solution for this.
EDITED
After Andrey answer I have tried this as well, but still does not work. maven-apt-plugin cannot see the classes generated classes located in target/java. I have tried with <additionalSourceRoots> with different syntax without any luck.. :(
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<additionalSourceRoots>
<additionalSourceRoot>target/java</additionalSourceRoot>
</additionalSourceRoots>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
Thanks
Maven build helper pligin will do the job.
Then just add more source roots in maven-apt-plugin with "additionalSourceRoots" parameter.
Our problem was that we had some classes in directory1 and directory2 that was used by the classes in directory3. The classes in directory3 was the classes with JPA annotations. We also found that it is important to put the directory with JPA annotated classes as the last directory, otherwise there was no classes generated by the apt plugin.
Surprisingly enough I tried to add additional sourceDirectory tags and it worked for me:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<sourceDirectory>__directory1__</sourceDirectory>
<sourceDirectory>__directory2__</sourceDirectory>
<sourceDirectory>__directory3__</sourceDirectory>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>

Has eclipselink JPA2 Criteria API pom.xml configuration been simplified?

From my pom http://code.google.com/p/memorizeasy/source/browse/MemoPlatform/persistence/pom.xml:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>1.3.7</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- Without this, the annotation processor complains about persistence.xml not being present and fail -->
<compilerArguments>-Aeclipselink.persistencexml=src/main/resources/META-INF/persistence.xml -Aeclipselink.persistenceunits=com.mysimpatico_MemoPlatform-database_nbm_1.0-SNAPSHOTPU</compilerArguments>
<!-- For an unknown reason, the annotation processor is not discovered, have to list it explicitly -->
<processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
We discussed this last year here, and reported a relevant bug (no one cared about #eclipselink).
Note: I'm the author of the plugin.
To make configuration a lot simpler I would recommend you test: https://github.com/ethlo/eclipselink-maven-plugin.
With EclipseLink 2.2.0, it works for me without specifying the processor. The compiler argument is still needed.

Resources