How to properly build executable JAR?

Hi there! I’m having hard time deploying my application (Spring Boot 3 + Vaadin 24 + Gradle) to production as executable JAR.

Best I’ve achieved so far is ./gradlew vaadinBuildFrontend bootJar -x test (I’m omitting the test task, because tests take about 10 minutes in total, I’ve made sure they pass though).

This command will result in a nice JAR within ./build/libs directory, but the Notifications Vaadin class does not quite work. Whenever I execute Notifications.show, the frontend will display an empty notification - no message.

However, notifications work on running this application using Gradle (i.e. ./gradlew bootRun). The message is displayed just fine.

I’d be really, really happy if someone could navigate me into the right solution as I’m stuck with these issues for a couple of hours :slightly_smiling_face:

Here’s my build.gradle:

plugins {
    id 'java'
    id 'application'
    id 'org.springframework.boot' version '3.1.1'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'com.vaadin' version '24.1.10'
}

group = 'com.demo'
version = '1.0.0'

java {
    sourceCompatibility = '17'
}

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

ext {
    set('vaadinVersion', "24.1.3")
    set('jjwtVersion', "0.11.5")
}

jar {
    duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
    from {
        configurations.runtimeClasspath.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }

}

vaadin {
    pnpmEnable = true
    productionMode = true
    generateBundle(productionMode)
    optimizeBundle(productionMode)
    vaadinClean
    vaadinBuildFrontend
}

dependencies {
    // lots of dependencies
}

dependencyManagement {
    imports {
        mavenBom "com.vaadin:vaadin-bom:${vaadinVersion}"
    }
}

tasks.named('test') {
    useJUnitPlatform()
}

Only notification broken or other components as well? Where are you using it? Within a specific class or all over the place in your app? When only Notification is broken, the simplest fix / workaround would be to add @Uses(Notification.class) to your main layout

Hi, the problem seems to be solved for now. Only Notifications were broken. I don’t quite know what happened that it works now. I abandoned the problem for these 2 days and made a lot of changes elsewhere in code. I’ve just realized that it works now.

If I come across this problem once again, I’ll make sure I try your solution :d