QueryDSL annotation processor - jpa classifier no longer works - gradle

My annotation processing has suddenly stopped working. I've made no known changes to my configuration and haven't been able to find any references to the error I'm getting.
Gradle Version: 7.5.1
QueryDSL Version: 5.0.0
build.gradle:
implementation "com.querydsl:querydsl-core:${querydslVersion}"
implementation "com.querydsl:querydsl-jpa:${querydslVersion}"
implementation "com.querydsl:querydsl-apt:${querydslVersion}"
...
annotationProcessor ("javax.annotation:javax.annotation-api:1.3.2")
annotationProcessor ("org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final")
annotationProcessor ("com.querydsl:querydsl-apt:${querydslVersion}")
annotationProcessor ("com.querydsl:querydsl-apt:${querydslVersion}:jpa")
Error:
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':annotationProcessor'.
> Could not find querydsl-apt-5.0.0-jpa.jar (com.querydsl:querydsl-apt:5.0.0).
Searched in the following locations:
file:/Users/devuser/.m2/repository/com/querydsl/querydsl-apt/5.0.0/querydsl-apt-5.0.0-jpa.jar
Found a work around (9/24):
The version of querydsl-jpa is controlled by my JHipster BOM, which pulls in 5.0.0. But if I specify the 4.4.0 version in my annotation processor it works. So it seems like the behavior changed in 5.0.0, or the classifier needs to be specified in some other way. But this is how I got it to work again.
implementation group: 'com.querydsl', name:'querydsl-jpa', version:'+'
annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', classifier: 'jpa', version: '4.4.0'

Related

gradle build failed due to dependency lock state

i have newly added a below dependency into my project
implementation 'org.jdbi:jdbi3-oracle12:3.29.0'
these are the dependencies which i already have in my project.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.data:spring-data-jpa'
implementation 'org.hibernate:hibernate-core'
// Oracle JDBC drivers
implementation("com.oracle.database.jdbc:ojdbc11")
implementation("com.oracle.database.jdbc:ucp")
// Additional Jars for using Oracle Wallets
implementation("com.oracle.database.security:oraclepki")
implementation("com.oracle.database.security:osdt_core")
implementation("com.oracle.database.security:osdt_cert")
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.jdbi:jdbi3-core:3.28.0'
implementation 'org.jdbi:jdbi3-oracle12:3.29.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-inline:4.5.1'
}
while adding the new dependency and doing gradle build. i'm getting the below error. can some one guide me how to fix this?
Execution failed for task ':compileJava'.
Could not resolve all files for configuration ':compileClasspath'.
Resolved 'org.jdbi:jdbi3-oracle12:3.29.0' which is not part of the dependency lock state
Resolved 'com.oracle.database.jdbc:ojdbc8:21.3.0.0' which is not part of the dependency lock state

Netty HTTP/3 codec dependency giving an error in Gradle

I'm currently working on implementing HTTP3 server using the Gradle version 7.3 on a Ubuntu 20.04 VM. But QUIC codec (0.0.20.Final) and HTTP/3 codec (0.0.11.Final) dependencies produce the following error.
Could not find netty-incubator-codec-native-quic-0.0.25.Final-${os.detected.name}-${os.detected.arch}.jar (io.netty.incubator:netty-incubator-codec-native-quic:0.0.25.Final).
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Following are the dependencies I used
implementation 'io.netty.incubator:netty-incubator-codec-quic:0.0.20.Final:linux-x86_64'
implementation 'io.netty.incubator:netty-incubator-codec-http3:0.0.11.Final'
As a temporary solution I downloaded the jar of the dependency from here and referenced it in the build.gradle file.
implementation ("io.netty.incubator:netty-incubator-codec-quic:0.0.20.Final:linux-x86_64")
implementation (files("libs/netty-incubator-codec-http3-0.0.11.Final.jar"))
Gradle is struggling to parse the classifier for the quic dependency, which is a property defined in terms of other properties, which are meant to be detected at build-time.
To work around that, exclude the quic dependency from your http3 dependency, and instead pull in quic directly:
implementation ( "io.netty.incubator:netty-incubator-codec-http3:0.0.11.Final" ) {
exclude group: "io.netty.incubator"
}
implementation "io.netty.incubator:netty-incubator-codec-native-quic:0.0.27.Final"
runtimeOnly ( group: "io.netty.incubator", name: "netty-incubator-codec-native-quic", classifier: "osx-x86_64" )
runtimeOnly ( group: "io.netty.incubator", name: "netty-incubator-codec-native-quic", classifier: "linux-x86_64" )

Gradle dependency visible only for annotation processor

I want to add a dependency to Gradle project that is visible to the annotation processor during the processing.
But at the same time I do not want this dependency to be accessible from the source code.
How can this be done?
If you are using a recent version of Gradle, then annotation processor dependencies are declared in a separate configuration annotationProcessor that is only resolved for that purpose.
Versions prior to 4.6 used to find them from the compile classpath, and if you have to use old versions, I don't think there is much you can do.
Example for 4.6+:
dependencies {
annotationProcessor 'com.google.dagger:dagger-compiler:2.8'
}
If your annotation processor requires any other dependencies for compiling your source code, you have no choice but to add them to the compile classpath, which will make them visible in an IDE. But you can use the compileOnly configuration to limit the scope so they won't be visible at runtime or selected as a transitive dependency. Example:
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
}

java.lang.NoSuchMethodError: org.mockito.MockingDetails.getMockCreationSettings() - Gradle links same class twice for Mockito jar

I have configured the following dependencies in the build.gradle file.
testCompile "org.springframework.boot:spring-boot-starter-test"
testCompile "org.mockito:mockito-all:1.10.19"
And when running the tests getting the following error stack trace.
java.lang.NoSuchMethodError: org.mockito.MockingDetails.getMockCreationSettings()Lorg/mockito/mock/MockCreationSettings;
at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:107)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:81)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:69)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:56)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:289)
And I've tried to debug it. Found something weird in the IntelliJ linked jar files. Almost most of the classes in the Mockito jar displayed twice.
Refreshing gradle dependencies or cache clear both did not work.
After so many days, I figured out that the issue is with the mockito jar version mismatch.
Changing the version from mockito-all to mockito-core build.gradle to
testCompile "org.mockito:mockito-core:2.24.0"
testCompile ("org.springframework.boot:spring-boot-starter-test") {
exclude group: "org.mockito", module: "mockito-all"
}
fixed my problem.
Thanks

Spring Boot/Gradle/Querydsl project has the same dependency dependent on different versions of another dependency

I am having problems adding Querydsl to my Spring Boot project. I have the following dependencies in my build.gradle file:
dependencies {
annotationProcessor 'com.querydsl:querydsl-apt:4.1.3:jpa'
annotationProcessor 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.querydsl:querydsl-jpa:4.1.3'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.3.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-config-client:2.1.0.RELEASE'
implementation 'mysql:mysql-connector-java'
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation 'io.springfox:springfox-bean-validators:2.9.2'
implementation group: 'org.latencyutils', name: 'LatencyUtils', version: '2.0.3'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-inline:2.23.4'
}
The project builds fine, but when I run it, I get the following error:
An attempt was made to call the method com.google.common.collect.FluentIterable.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable; but it does not exist. Its class, com.google.common.collect.FluentIterable, is available from the following locations:
jar:file:/C:/Users/me/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/18.0/cce0823396aa693798f8882e64213b1772032b09/guava-18.0.jar!/com/google/common/collect/FluentIterable.class
jar:file:/C:/Users/me/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/20.0/89507701249388e1ed5ddcf8c41f4ce1be7831ef/guava-20.0.jar!/com/google/common/collect/FluentIterable.class
It was loaded from the following location:
file:/C:/Users/me/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/18.0/cce0823396aa693798f8882e64213b1772032b09/guava-18.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.FluentIterable
The Gradle window in IntelliJ shows the following:
Why does each instance of com.querydsl:querydsl-core:4.2.1 depend on a different version of guava?
The version 18.0 of Guava comes from querydsl and the 20.0 comes from spring-fox swagger.
spring-fox library expected that method of guava version 20.0 to be called. but called from 18.0. (because there are two guava library that has difference version in classpath)
you can use the following code to avoid conflict version of guava.
// QueryDsl
implementation("com.querydsl:querydsl-jpa:${querydslVersion}")
annotationProcessor("org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final")
annotationProcessor("com.querydsl:querydsl-apt:${querydslVersion}:jpa") {
exclude group: "come.google.guava"
}
annotationProcessor("com.google.guava:guava:20.0")

Resources