springgradlespring-data-jpaeclipselinkquerydsl

Eclipselink / Spring boot with Gradle. Getting ClassNotFoundException for QueryDslPredicateExecutor


A simple executable jar generated using the following gradle script is giving ClassNotFoundException

group 'com.acme'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.1.RELEASE")
    }


}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'acme-project1'
    version =  '0.1.0'
}

jar {
    manifest {
        attributes 'Main-Class': 'com.acme.ApplicationLoader'
        attributes 'Spring-Boot-Classes': 'BOOT-INF/classes/'
        attributes 'Spring-Boot-Lib': 'BOOT-INF/lib/'
    }
}


repositories {
    mavenCentral()
    mavenLocal()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

ext {
    queryDslVersion = '4.1.4'

}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-data-jpa"){
        exclude group: "org.hibernate", module: "hibernate-entitymanager"
    }
    compile("org.springframework.boot:spring-boot-starter-data-rest")

    compile "com.querydsl:querydsl-root:$queryDslVersion"
    compile "com.querydsl:querydsl-jpa:$queryDslVersion"
    compile "com.querydsl:querydsl-apt:$queryDslVersion:jpa"

    compile("com.a:acme-persistence:1.0-SNAPSHOT")

    testCompile("junit:junit")

}

Note: All the DAO layer code is packaged in a separate jar acme-persistence, which is added as compile() dependency

Note2: I have another project, which also relies on acme-persistence, which is build using maven and is working fine. After unjaring and comparing the packages, everything was similar except the META-INF/MANIFEST.MF file. In the working jar there were these lines:

Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/

which were missing from the gradle-built jar. So I added those to the gradle project and verified after unjaring that those lines are present. However, am still getting the same error!

The error:

java.lang.NoClassDefFoundError: org/springframework/data/querydsl/QueryDslPredicateExecutor
        at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_25]
        at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_25]
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_25]
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:455) ~[na:1.8.0_25]
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_25]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:367) ~[na:1.8.0_25]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_25]
        at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_25]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_25]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93) ~[acme-project1-0.1.0.jar:na]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_25]
        at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_25]
        at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_25]
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_25]
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:455) ~[na:1.8.0_25]
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_25]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:367) ~[na:1.8.0_25]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_25]
        at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_25]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_25]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93) ~[acme-project1-0.1.0.jar:na]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_25]
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:274) ~[spring-core-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.data.repository.config.RepositoryBeanNameGenerator.getRepositoryInterfaceFrom(RepositoryBeanNameGenerator.java:90) ~[spring-data-commons-2.0.6.RELEASE.jar!/:2.0.6.RELEASE]
        at org.springframework.data.repository.config.RepositoryBeanNameGenerator.generateBeanName(RepositoryBeanNameGenerator.java:54) ~[spring-data-commons-2.0.6.RELEASE.jar!/:2.0.6.RELEASE]
        at org.springframework.data.repository.config.RepositoryConfigurationSourceSupport.generateBeanName(RepositoryConfigurationSourceSupport.java:98) ~[spring-data-commons-2.0.6.RELEASE.jar!/:2.0.6.RELEASE]
        at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:134) ~[spring-data-commons-2.0.6.RELEASE.jar!/:2.0.6.RELEASE]
        at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:60) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]

Solution

  • The problem was spring-data-jpa-1.12.2 had class QueryDslPredicateExecutor, while it was renamed to QuerydslPredicateExecutor in spring-data-jpa-2.6.0.

    Notice the small d vs capital D!