0
votes

I'm developing an IntelliJ plugin using the Gradle build system. This plugin uses a common model which is a maven project.

I've included mavenLocal in my gradle repositories and also added the compile-time dependency in 'dependencies'.

The code is compiling fine but I'm getting java.lang.NoClassDefFoundError in runtime. When I checked the dependencies in gradle it is not listing all dependencies for local maven jar(model library).

Below is a stripped version of my build.gradle

plugins {
    id 'java'
    id 'org.jetbrains.intellij' version '0.4.1'
    id 'maven'
}
group 'oracle.nosql'

repositories {
    //mavenCentral()
    mavenLocal()
}
dependencies {
    compile 'oracle.nosql:oracle.nosql.model.common:1.0.0' //this is maven lib
    compile 'oracle.nosql:oracle.nosql.model.cloud:1.0.0' //this is maven lib
}
apply plugin: 'maven'

Below is the output of gradle dependencies

compileClasspath - Compile classpath for source set 'main'.M
+--- oracle.nosql:oracle.nosql.model.common:1.0.0M
+--- oracle.nosql:oracle.nosql.model.cloud:1.0.0M
|    \--- com.fasterxml.jackson.core:jackson-databind:2.9.7M
|         +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0M
|         \--- com.fasterxml.jackson.core:jackson-core:2.9.7M
\--- com.jetbrains:ideaIC:2018.3.2M

But in maven for model dependency is different.

    mvn dependency:build-classpath

    oracle.nosql.model.cloud ---
    [INFO] Dependencies classpath:
    ...\.m2\repository\oracle\nosql\oracle.nosql.model.common\1.0.0\oracle.nosql.model.common-1.0.0.jar;
D:\oracle-nosql-cloud-sdk-18.298\java\lib\nosqldriver.jar;
...\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.7\jackson-databind-2.9.7.jar;...\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;...\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.7\jackson-core-2.9.7.jar;...\.m2\repository\junit\junit\4.12\junit-4.12.jar;

In particular D:\oracle-nosql-cloud-sdk-18.298\java\lib\nosqldriver.jar is missing from gradle dependency.

I think this is causing java.lang.NoClassDefFoundError.

1
Are you sure that you have the same dependency list in the build.gradle as defined in the pom.xml? - DrHopfen
@DrHopfen Do I need to include dependency of pom.xml in build.gradle also? But here it is resolving from transitive dependency of pom like jackson? - akshay
Gradle is resolving the transitive dependencies as well. But if your needed jar is a direct or transitive dependency of an artifact not mentioned in you build.gradle you will face the described issue. - DrHopfen

1 Answers

1
votes

Given the absolute path of D:\oracle-nosql-cloud-sdk-18.298\java\lib\nosqldriver.jar, I will assume you have a system dependency declared in your Maven library.

These dependencies are not included by Gradle for the compileClasspath or runtimeClasspath resolution.

You will have to add back this dependency as a file dependency in your Gradle build.