Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle: failed to compute classpath #147

Open
serhiynovos opened this issue Nov 24, 2021 · 4 comments
Open

Gradle: failed to compute classpath #147

serhiynovos opened this issue Nov 24, 2021 · 4 comments
Labels
type:question A user question

Comments

@serhiynovos
Copy link

serhiynovos commented Nov 24, 2021

When I try to build native image using command ./gradlew bootBuildImage I get the next error:

Paketo Spring Boot Buildpack 4.4.2
    [creator]       https://github.com/paketo-buildpacks/spring-boot
    [creator]     unable to invoke layer creator
    [creator]     failed to compute classpath
    [creator]     manifest does not contain Spring-Boot-Classpath-Index
    [creator]     ERROR: failed to build: exit status 1

All logs:

./gradlew bootBuildImage
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

> Task :bootBuildImage
Building image 'docker.io/library/stomp:0.0.1-SNAPSHOT'

 > Pulling builder image 'docker.io/paketobuildpacks/builder:tiny' ..................................................
 > Pulled builder image 'paketobuildpacks/builder@sha256:2e48ef36f9e17d72a9dc37f7c2800fcde82c3018bdef6836c4ade8a7e06ff69f'
 > Pulling run image 'docker.io/paketobuildpacks/run:tiny-cnb' ..................................................
 > Pulled run image 'paketobuildpacks/run@sha256:6cec91e026cbdf498efd3de44d26642241591561106714e578fec9a354f2627f'
 > Pulling buildpack image 'gcr.io/paketo-buildpacks/java-native-image:5.5.0' ..................................................
 > Pulled buildpack image 'gcr.io/paketo-buildpacks/java-native-image@sha256:0def9132cae1a8d9ed577c4dd3c92d650bb8d333fa93df1b6ff97f5af7ffd055'
 > Executing lifecycle version v0.13.0
 > Using build cache volume 'pack-cache-e18067e752a1.build'

 > Running creator
    [creator]     ===> DETECTING
    [creator]     5 of 12 buildpacks participating
    [creator]     paketo-buildpacks/ca-certificates 2.3.2
    [creator]     paketo-buildpacks/graalvm         6.3.0
    [creator]     paketo-buildpacks/executable-jar  5.1.2
    [creator]     paketo-buildpacks/spring-boot     4.4.2
    [creator]     paketo-buildpacks/native-image    4.2.0
    [creator]     ===> ANALYZING
    [creator]     Restoring metadata for "paketo-buildpacks/ca-certificates:helper" from app image
    [creator]     ===> RESTORING
    [creator]     ===> BUILDING
    [creator]     
    [creator]     Paketo CA Certificates Buildpack 2.3.2
    [creator]       https://github.com/paketo-buildpacks/ca-certificates
    [creator]       Launch Helper: Contributing to layer
    [creator]         Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
    [creator]     
    [creator]     Paketo GraalVM Buildpack 6.3.0
    [creator]       https://github.com/paketo-buildpacks/graalvm
    [creator]       Build Configuration:
    [creator]         $BP_JVM_VERSION              11.*            the Java version
    [creator]       Launch Configuration:
    [creator]         $BPL_JVM_HEAD_ROOM           0               the headroom in memory calculation
    [creator]         $BPL_JVM_LOADED_CLASS_COUNT  35% of classes  the number of loaded classes in memory calculation
    [creator]         $BPL_JVM_THREAD_COUNT        250             the number of threads in memory calculation
    [creator]         $JAVA_TOOL_OPTIONS                           the JVM launch flags
    [creator]       GraalVM JDK 11.0.12: Contributing to layer
    [creator]         Downloading from https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.2.0/graalvm-ce-java11-linux-amd64-21.2.0.tar.gz
<============-> 94% EXECUTING [2m 10s]
> :bootBuildImage

<============-> 94% EXECUTING [2m 36s]


<============-> 94% EXECUTING [3m 7s]

    [creator]         Verifying checksum
    [creator]         Expanding to /layers/paketo-buildpacks_graalvm/jdk
    [creator]         Adding 128 container CA certificates to JVM truststore
    [creator]       GraalVM Native Image Substrate VM 11.0.12
    [creator]         Downloading from https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.2.0/native-image-installable-svm-java11-linux-amd64-21.2.0.jar
    [creator]         Verifying checksum
    [creator]         Installing substrate VM
    [creator]     Processing Component archive: /tmp/6fc4c6becbe0331aa0a038660fde7c4769c6d6e97d5a90a716a898188d3a6df9/native-image-installable-svm-java11-linux-amd64-21.2.0.jar
    [creator]     Installing new component: Native Image (org.graalvm.native-image, version 21.2.0)
    [creator]         Writing env.build/JAVA_HOME.override
    [creator]         Writing env.build/JDK_HOME.override
    [creator]     
    [creator]     Paketo Executable JAR Buildpack 5.1.2
    [creator]       https://github.com/paketo-buildpacks/executable-jar
    [creator]       Class Path: Contributing to layer
    [creator]         Writing env.build/CLASSPATH.delim
    [creator]         Writing env.build/CLASSPATH.prepend
    [creator]     
    [creator]     Paketo Spring Boot Buildpack 4.4.2
    [creator]       https://github.com/paketo-buildpacks/spring-boot
    [creator]     unable to invoke layer creator
    [creator]     failed to compute classpath
    [creator]     manifest does not contain Spring-Boot-Classpath-Index
    [creator]     ERROR: failed to build: exit status 1

> Task :bootBuildImage FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootBuildImage'.
> Builder lifecycle 'creator' failed with status code 145

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3m 34s

Gradle build file

plugins {
    id 'org.springframework.boot' version '2.5.6'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'war'
    id 'org.springframework.experimental.aot' version '0.10.5'
    id 'org.graalvm.buildtools.native' version '0.9.4'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    maven { url 'https://repo.spring.io/release' }
    mavenCentral()
}

dependencies {

    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-websocket'
    implementation 'org.springframework.kafka:spring-kafka'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.kafka:spring-kafka-test'
    testImplementation 'org.springframework.security:spring-security-test'

    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
}

test {
    useJUnitPlatform()
}

bootBuildImage {
    builder = "paketobuildpacks/builder:tiny"
    environment = [
            "BP_NATIVE_IMAGE" : "true"
    ]
    buildpacks = ["gcr.io/paketo-buildpacks/java-native-image:5.5.0"]
}

nativeBuild {
    classpath(processAotResources.outputs, compileAotJava.outputs)
}

nativeTest {
    classpath(processAotTestResources.outputs, compileAotTestJava.outputs)
} 
Java  version: java --version
java 11.0.10 2021-01-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.10+8-LTS-162, mixed mode)

OS: MacOS 12.0.1

@dmikusa dmikusa added the type:question A user question label Dec 1, 2021
@dmikusa
Copy link
Contributor

dmikusa commented Dec 1, 2021

Sorry for the delay.

What's happening is that the application is missing a Spring-Boot-Classpath-Index entry in the META-INF/MANIFEST.MF file. This entry should exist with modern Spring Boot apps. You're using Spring Boot 2.5.6, so it should have that entry.

What happens if you run ./gradlew assemble. Then unzip -p build/libs/demo-0.0.1-SNAPSHOT.jar META-INF/MANIFEST.MF? You should see something like this:

Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: io.paketo.demo.DemoApplication
Spring-Boot-Version: 2.5.7
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx

Note that Spring-Boot-Classpath-Index exists. Does it exist in your case?

If it is present in your machine, try running ./gradlew bootBuildImage again. The plugin to build the container image should take the JAR file built locally and pass that through to the buildpack to turn into a native image. So if it exists locally, I don't see why it would not exist when the buildpack runs.

Let me know what you find.

@JaneWardSandy
Copy link

@serrg1994 I had this issue before.
It seems you were build a war file, and bootBuildImage read Spring-Boot-Classpath-Index in MANIFEST.MF only store in jar file.
So you need to delete the line id 'war' in plugins in Gradle build file, then run ./gradlew bootBuildImage again, it should be fine.

@dmikusa
Copy link
Contributor

dmikusa commented Dec 2, 2021

Good catch @JaneWardSandy! Thanks for sharing that. Let me check with the Spring Boot team and see how we should handle this. If building a WAR does not add those entries, then it seems like the buildpack shouldn't require them to be there.

@dmikusa
Copy link
Contributor

dmikusa commented Dec 2, 2021

Looks like there is some talk of making Spring Boot executable WAR files have the same strict classpath ordering as executable JAR files. That should make the buildpack work if you are generating an executable WAR and want to build a native image.

spring-projects/spring-boot#19875

When that issue is resolved, we can revisit it and if there are still problems work them out then.

In the meantime, as was pointed out above. Make sure your project is building an executable JAR if you want to build native image binaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question A user question
Projects
None yet
Development

No branches or pull requests

3 participants