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

Issue: application.yml Not Loaded Correctly in Fat JAR Built with Shadow Plugin #947

Open
kaziasifjawwad opened this issue Aug 27, 2024 · 1 comment

Comments

@kaziasifjawwad
Copy link

Issue: application.yml Not Loaded Correctly in Fat JAR Built with Shadow Plugin

Description

I encountered an issue where the application.yml file is not being loaded correctly when packaging a Spring Boot application into a fat JAR using the com.github.johnrengelman.shadow plugin.

Steps to Reproduce

  1. Project Setup:

    • Spring Boot version: 2.7.7
    • Gradle version: 8.10 (Replace with your version)
    • Shadow plugin version: 8.1.1
    • Java version: 17
  2. Build the Fat JAR:

    • I used the following Gradle configuration to build the fat JAR:

      plugins {
          id 'application'
          id 'org.openjfx.javafxplugin' version '0.0.13'
          id 'com.github.johnrengelman.shadow' version '8.1.1'
      }
      
      shadowJar {
          archiveClassifier.set('all')
          mergeServiceFiles()
      
          from('src/main/resources') {
              into 'BOOT-INF/classes/'
              include '**/*.yml'
          }
      }
      
      application {
          mainClass = 'com.jawwad.posrestaurant.PosRestaurantApplication'
      }
  3. Run the Application:

    • After building the fat JAR, I executed it using:

      java -jar build/libs/posrestaurant-0.0.1-SNAPSHOT-all.jar

Observed Behavior

  • The application.yml file is present in both the root and BOOT-INF/classes/ directories within the JAR.
  • Despite this, Spring Boot fails to resolve placeholders defined in application.yml (e.g., ${backend.baseurl}) during the application startup.
  • The application throws an IllegalArgumentException indicating that the placeholder could not be resolved.

Expected Behavior

  • Spring Boot should correctly load application.yml from BOOT-INF/classes/ and resolve all placeholders defined within it.

Additional Information

  • The application runs correctly when built using the bootJar task or when using the non-fat JAR.
  • The issue appears to be specific to the configuration when using the Shadow plugin.

Logs and Output

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'backend.baseurl' in value "${backend.baseurl}"
    at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180)
    ...
@kyuri-code
Copy link

Same Issue to me, hoping any updates.

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

No branches or pull requests

3 participants
@kaziasifjawwad @kyuri-code and others