Spring Boot & QueryDSL with compilation error: due to QClass symbol not found - spring-boot

I am new to Querydsl , but I am having problems with generating Q classes.
I get a lot of errors that a Q'class' cannot be resolved , like this :
Cannot find symbol class QProduct
the code
private final QProduct qProduct = QProduct.product;
my project is built with :
spring-boot.version : 2.0.8 ;
Java version : 1.8 ;
Maven version : 3.0 ;
Hibernate version : 5.2.17 ;
postgresql : 42.2.5 ;
i'm use "maven-apt-plugin" for generated Q class.
porn.xml
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.2.1</version>
</dependency>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
I have already tried this solution but the problem persists
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>target/generated-sources/querydsl/java
</outputDirectory>
<processor>com.querydsl.apt.QuerydslAnnotationProcessor</processor>
<options>
<querydsl.logInfo>true</querydsl.logInfo>
<querydsl.listAccessors>false</querydsl.listAccessors>
<querydsl.useGetters>true</querydsl.useGetters>
<querydsl.unknownAsEmbeddable>true</querydsl.unknownAsEmbeddable>
</options>
</configuration>
</execution>
</executions>
I looked at other topic similar to mine but their solution does not work on my project
What is wrong?
Thanks!

Related

Kotlin Querydsl: cannot find javax.annotation.proceesing.Generated

I am following this example https://felixzett.com/articles/minimal-maven-kotlin-querydsl-example/ to implement querydsl in a Springboot Kotlin Maven project. Using the pom mentioned, I managed to generate the q classes after running mvn compile and can run mvn clean install successfully as well, but when I try to run the project locally, I get error in all the q classes.
java: cannot find symbol
symbol: class Generated
location: package javax.annotation.processing
I tried adding javax.annotation-api to the <annotationProcessPaths> element but it didn't work.
<annotationProcessorPath>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</annotationProcessorPath>
I also tried adding it as a dependency, within that <plugin> element or in the main <dependencies> element, but these didn't work as well.
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
May I know if anyone has any idea how to solve this?
Update:
I have both kotlin-maven-plugin and maven-compiler-plugin in my pom. I realise if I comment out the maven-compiler-plugin then the error is gone. But I am not sure if other parts of the app will be affected if it doesn't have this plugin.
Does anyone know if it is ok to just have the kotlin-maven-plugin, or how I should modify maven-compiler-plugin for the 2 plugins to work together?
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>kapt</id>
<phase>generate-sources</phase>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<classifier>jpa</classifier>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/test/kotlin</sourceDir>
<sourceDir>target/generated-sources/kapt/test</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
<plugin>jpa</plugin>
<plugin>all-open</plugin>
</compilerPlugins>
<pluginOptions>
<option>all-open:annotation=javax.persistence.Entity</option>
<option>all-open:annotation=javax.persistence.MappedSuperclass</option>
<option>all-open:annotation=javax.persistence.Embeddable</option>
</pluginOptions>
<jvmTarget>1.8</jvmTarget>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
It seems like it is due to the Java version in the maven-compiler-plugin. After I changed it from 1.8 to 11, I do not get the error even if I have both kotlin-maven-plugin and maven-compiler-plugin.
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
Also change the java version to 11 in the <properties> element.
<properties>
<java.version>11</java.version>
</properties>

Can't generate QueryDSL's QClass when upgrading to 5.0.0 (com.querydsl.sql.Configuration is not registered)

I upgraded my QueryDSL's version to 5.0.0 (for the JTS upgrade) but now, the plugin throw an error when regenerating QClass using mvn clean install : com.querydsl.sql.Configuration is not registered.
Here is my configuration :
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
<options>
</options>
</configuration>
</execution>
</executions>
</plugin>
Use the dependency below.
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<classifier>jakarta</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<classifier>jakarta</classifier>
<version>${querydsl.version}</version>
</dependency>
You're encouraged to use:
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
<classifier>jpa</classifier>
</dependency>
Instead of the apt-maven-plugin for Querydsl 4.0.0 and higher.
Hello I quite have the same issue. In order to make it work I specified with the apt-maven-plugin only the folders where my entities were like here :
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<includes>
<include>common.persistence.entity.**</include>
<include>security.persistence.entity.**</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>target/generated-sources/annotations</outputDirectory>
<processors>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</processors>
</configuration>
Don't know if this would help you but. You should giv it a try !

Scala version error with Spark 2 & ElasticSearch 5.4.2

I'm using Spark 2.2 (build with Scala 2.11.8) to index my data into ElasticSearch 5.4.2.
ElasticSearch :
My project spark use this pom.xml :
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-hadoop</artifactId>
<version>5.4.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-spark-20_2.11</artifactId>
<version>5.4.2</version>
</dependency>
When I run my job, I get this exception :
Caused by: java.lang.NoSuchMethodError: scala.reflect.api.JavaUniverse.runtimeMirror(Ljava/lang/ClassLoader;)Lscala/reflect/api/JavaMirrors$JavaMirror;
at org.elasticsearch.spark.serialization.ReflectionUtils$.org$elasticsearch$spark$serialization$ReflectionUtils$$checkCaseClass(ReflectionUtils.scala:42)
at org.elasticsearch.spark.serialization.ReflectionUtils$$anonfun$checkCaseClassCache$1.apply(ReflectionUtils.scala:84)
at org.elasticsearch.spark.serialization.ReflectionUtils$$anonfun$checkCaseClassCache$1.apply(ReflectionUtils.scala:83)
I know my problem is Scala version (build/run) ...
Thanks for your help
EDIT BUILD POM :
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<argLine>-J-Xms128m</argLine>
<argLine>-J-Xmx512m</argLine>
<argLine>-J--XX:MaxPermSize=300m</argLine>
<argLine>-Djava.net.preferIPv4Stack=true</argLine>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>UBER</shadedClassifierName>
<artifactSet>
<includes>
<include>com.databricks:spark-csv_${scala.compact.version}</include>
<include>org.apache.commons:commons-csv</include>
<include>org.elasticsearch:elasticsearch-hadoop</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

WSDL is not generated

I have added below plugin into pom.xml but I dont know where the wsdl is generated or may be the wsdl is not generated. I do not get any error while doing clean & install
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>${cxf.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<className>com.alu.usddomega.ws.facade.customeroffer.CustomerOfferFacadeImpl</className>
<outputFile>${basedir}/src/main/java/wsdl/CusttomerOffer.wsdl</outputFile>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
<genServer>false</genServer>
<targetNamespace>http://customeroffer.manage.ws.usddomega.alu.com/</targetNamespace>
<attachWsdl>true</attachWsdl>
<serviceName>getCustomerOffer</serviceName>
<databinding>ManageCustomerOffer</databinding>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>
The WSDL should be at:
<outputFile>${basedir}/src/main/java/wsdl/CusttomerOffer.wsdl</outputFile>

gmaven-plugin works for groovy 1.7.5 but not for 2.1.0

I have working maven 2 setup which compiles jUnit tests written in groovy. Both java and groovy tests are located at /src/test/java
See a snapshot of the pom.xml
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<sources>
<fileset>
<directory>${pom.basedir}/src/test/java</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileset>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.7.5</version>
<scope>test</scope>
</dependency>
When I upgrade to plugin version 1.5 and groovy 2.1.0, */.groovy files are ignored. Has anybody met up with this problem?
I found this page https://confluence.atlassian.com/display/CLOVER/Compiling+Groovy+with+GMaven+plugin
Note that you must put your Groovy Classes and Tests under src/main/groovy and src/test/groovy respectively.
Following configuration based on that page seems to work:
<!-- Groovy and Maven https://confluence.atlassian.com/display/CLOVER/Compiling+Groovy+with+GMaven+plugin -->
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>${gmaven.version}</version>
<configuration>
<providerSelection>2.0</providerSelection>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-2.0</artifactId>
<version>${gmaven.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
And in dependencies of course
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
And in properties
<properties>
<gmaven.version>1.5</gmaven.version>
<groovy.version>2.1.8</groovy.version>
</properties>
Ok, this configuration works for maven 2.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.4</version>
<configuration>
<providerSelection>2.0</providerSelection>
<sourceEncoding>UTF-8</sourceEncoding>
</configuration>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<sources>
<fileset>
<directory>${pom.basedir}/src/test/java</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileset>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
I experience the same problem, but downgrading to gmaven 1.4 solves the problem (using groovy-all 2.3.2)
First, each GMaven provider compiles against a particular version of Groovy, so there can be issues if Groovy breaks something with a point release. Second, GMaven is no longer maintained (that's why you don't see any providers for newer Groovy versions). I recommend switching to GMavenPlus or the Groovy-Eclipse compiler plugin for Maven.

Resources