Gradle not satisfied with anything

I am trying to build a Docker image and try to use provided Gradle to build content.
Building with Gradle 4.4 fails with

exec /usr/local/openjdk-8/bin/java -Dorg.gradle.appname=gradlew -classpath /path/to/gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain wrapper                                                                                                             
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain 

This happens every single time I try to build with the already included gradlew and gradle-wrapper.jar.
After trying every fix out there provided on the internet and still failing I downloaded Gradle 4.4 manually, changed gradlew to use this one instead, just to be extra sure that the provided jar is not faulty. Then this happens:

exec /usr/local/openjdk-8/bin/java -Dorg.gradle.appname=gradlew -classpath /path/to/gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain wrapper       
Exception in thread "main" java.lang.NoClassDefFoundError: org/gradle/cli/CommandLineParser                                                
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:41)                                                            
Caused by: java.lang.ClassNotFoundException: org.gradle.cli.CommandLineParser                                                              
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)                                                                      
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)                                                                           
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)                                                                   
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)                                                                           
        ... 1 more         

The specific part of the Dockerfile that is involved in the problem. The error occurs on the last line seen in this snippet:

...

FROM openjdk:8 as apps
COPY settings.gradle /src/settings.gradle
COPY shared /src/shared/
COPY login /src/login/
RUN cd /src/login; ./gradlew installDist;

...

The only two relevant lines in the aforeseen settings.gradle are here:

include ':shared'
project(':shared').projectDir = new File(settingsDir, './shared')

...

include 'login'

This is the build.gradle in the shared folder:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'kotlin'

sourceCompatibility = 1.8
version = 0.1

repositories {
    jcenter()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"

    compile 'org.slf4j:slf4j-api:1.7.7'
    compile 'org.mongodb:mongodb-driver:3.0.2'
    compile 'org.mongodb.morphia:morphia:1.0.0'
    compile 'org.apache.commons:commons-email:1.4'
    compile 'org.apache.httpcomponents:httpclient-osgi:4.5'
    compile 'commons-lang:commons-lang:2.6'
    compile 'commons-net:commons-net:3.3'
    compile 'commons-io:commons-io:2.4'
    compile 'com.google.inject:guice:4.0'
    compile 'com.spotify:docker-client:3.3.5'
    compile 'joda-time:joda-time:2.8.2'

    /**
     * ==== There are some transitive dependencies issues between master, minion and shared ====
     * Update 2019-07-15: master now declares its own dependcy on jackson and excludes the
     * one provided by :shared
     */

    // minon requires 2.6.x
    compile 'com.fasterxml.jackson.core:jackson-databind:2.6.0'
    compile "com.fasterxml.jackson.module:jackson-module-kotlin:2.6.7"
}

buildscript {
    ext.kotlin_version = '1.2.41'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

This is the build.gradle in the login folder:

buildscript {
    ext.kotlin_version = '1.2.41'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

group 'group.group'
version '1.0'

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

mainClassName = "nonexistent"

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

    compileOnly 'org.apache.httpcomponents:httpclient:4.3.6'
    compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
    compileOnly files("libs/abcam.jar")

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

Before you answer, please note:

  • The gradle-wrapper.jar is definitely checked out in the VCS and I downloaded one manually, anyway.
  • Before I tried to build the image, it has already been working in the past. Yet, it suddenly does not, anymore.
  • ./gradlew jar or any of the other proposed fixes did not work or even change anything noticably.

I would appreciate any constructive help, as this is a bit urgent.

Any help? I’d really need some on this issue.

It looks like you aren’t copying the Gradle wrapper into your docker container which is why the class is missing.

Greetings @JLLeitschuh, thanks for your response.

There is another thing that gets built with this gradle wraper directly after the snippet I have shown and it gets built flawlessly, every time. If there was something missing, it wouldn’t work at all.

It seems like you should be copying the gradle directory from your application root as @JLLeitschuh mentioned, but there’s no indication from your Dockerfile snippet that you’re doing that.

COPY gradle src/gradle

It also looks like you’re trying to run gradle from the login directory directly. Don’t people usually run gradle from the root (/src) most of the time?

Why not something like:

./gradlew :login:someTask

Things can could be helpful for debugging:

  • Sharing your full Dockerfile might be helpful to understand why a subsequent command is working, but not this one.
  • Include you directory layout with the location of various gradlew/gradle files.
  • Provide a minimal project that recreates this

@Appu_Goundan
Thank you for your interest in joining the conversation.

I posted the Dockerfile snippet that is remotely relevent to the task at hand. Everything I did not post is not related to this snippet. The Dockerfile contains a multi-stage build. There is only 1 stage preceding the snippet and it is not related to the shown snippet, therefore there is nothing else in the Dockerfile that could have an effect on the shown part, at all.

That said, it is important to note that, as already mentioned, the same gradlew is doing its job fine for the second task, but not the first one. So something has to be really fishy about it, since a bad gradlew shouldn’t work at all in any case.

Since even after these explanations many people seem to doubt my trustworthiness, I am showing the preceding part of the Dockerfile:

FROM node:6.16-stretch as cloudprint_frontend
COPY solutions /src/solutions
RUN cd /src/solutions/src/main/html5; \
    npm install -g gulp-cli bower; \
    npm install; \
    bower --allow-root install; \
    gulp build;

I hope this puts the final nail in the coffin of the aforementioned doubts.

I don’t think it’s an issue with trust. It’s just helpful to get as much information as possible when debugging.

There is another thing that gets built with this gradle wraper directly after the snippet I have shown and it gets built flawlessly, every time. If there was something missing, it wouldn’t work at all.

^^^ I think it’s important to clarify what this means too. That’s the interesting part of the docker file that matters.

Despite all the information, it still looks like you need to include the gradle directory in your build for this to work, as that is what appears to be missing.

What’s also helpful would be:

  • How do you run this build locally
  • A full directory structure with locations of gradlew and gradle (directory) of your project