Skip to content
Advertisement

BootJar didn’t create BOOT-INF folder after spring boot migration from 1.5.8 to 2.1.14-RELEASE

I have done the migration of the Spring Boot Application from 1.5.8 to 2.1.14-RELEASE and using gradle as a build script. I am using spring-boot-gradle-plugin and spring-boot-dependency-management plugins. In our spring boot project, we are creating multiple executable jar files by creating tasks for each jar as below

// During Migration changed from Jar to BootJar
task eurekaAppJar(type: BootJar) {
    baseName = 'eurekaJar'
    version = '0.0.1'
    println sourceSets.main.output
    manifest {
        attributes 'Main-Class': "org.springframework.boot.loader.JarLauncher"
        attributes 'Start-Class': "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
        attributes 'Implementation-Version': "001"
    }
    bootJar {
        mainClassName = "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
    }
    from(sourceSets.main.output) {
    }
}
// During Migration changed from Jar to BootJar
task oAuthConfigJar(type: BootJar) {
    baseName = 'oAuthConfigJar'
    version = '0.0.1'

    manifest {
        attributes 'Main-Class': "org.springframework.boot.loader.JarLauncher"
        attributes 'Start-Class': "com.abc.abcCompany.service.authserver.AuthServerApplication"
        attributes 'Implementation-Version': "001"

    }
    springBoot {
        mainClassName = "com.abcCompany.service.authserver.AuthServerApplication"
    }
    from(sourceSets.main.output) {
    }
}
// During migration changed from BootRepackage to BootJar
task eurekaBoot(type: BootJar, dependsOn: eurekaAppJar) {
    mainClassName = 'com.abc.abcCompany.service.eurekaApp.EurekaApplication'
// During migration commented the below code
//        customConfiguration = "eurekaconfiguration"
//        withJarTask = eztrackerEurekaJar
}


// During migration changed from BootRepackage to BootJar
task oAuthConfigJarBoot(type: BootJar, dependsOn: oAuthConfigJar) {
    println " Executing eztrackerApiGatewayBoot task"
    mainClassName = 'com.abc.abcCompany.service.authserver.AuthServerApplication'
// During migration commented the below code
//        customConfiguration = "zuulconfiguration"
//        withJarTask = eztrackerApiGatewayJar
}


bootJar.dependsOn = [eurekaBoot, oAuthConfigJarBoot]

bootJar.enabled = false

In the above code after executing either gradle assemble, It has created two executable jar files eurekaJar-0.0.1.jar, oAuthConfigJar-0.0.1.jar.

Here is my question:

Before the spring boot migration, in the above jars the folder structure is as below:

eurekaJar-0.0.1.jar 
   -- org
   -- META-INF
   -- BOOT-INT
         -- lib
              -- dependencies (jars)
         -- classes
               -- applicationclasses

after the migration below is the folder structure

eurekaJar-0.0.1.jar 
   -- org
   -- META-INF
   -- applicationclasses

so after the migration there is no BOOT-INF folder and dependencies(lib folder)

Because of the above issue my executable jar is not running.

Any comment is appreciated.

Advertisement

Answer

Rather than using from, which will add files directly to the jar, you should configure the classpath of the BootJar tasks. Jar files on the classpath will be packaged in BOOT-INF/lib and directories will be packaged in BOOT-INF/classes.

For reference, you can see how Spring Boot configures the classpath of the default bootJar task in its own plugin here. From what you’ve shown above, you probably want to use the runtime classpath of the main source set too.

Here’s a complete example for your eurekaAppJar:

import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
    id 'org.springframework.boot' version '2.1.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

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

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

task eurekaAppJar(type: BootJar) {
    baseName = 'eurekaJar'
    version = '0.0.1'
    manifest {
        attributes 'Main-Class': "org.springframework.boot.loader.JarLauncher"
        attributes 'Start-Class': "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
        attributes 'Implementation-Version': "001"
    }
    mainClassName = "com.abc.abcCompany.service.eurekaApp.EurekaApplication"
    classpath sourceSets.main.runtimeClasspath
}

This jar can then be built with the following command:

$ ./gradlew eurekaAppJar

Its classes and dependencies are packaged in BOOT-INF/classes and BOOT-INF/lib respectively:

$ unzip -l build/libs/eurekaJar-0.0.1.jar 
Archive:  build/libs/eurekaJar-0.0.1.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  04-04-2019 02:23   org/
        0  04-04-2019 02:23   org/springframework/
        0  04-04-2019 02:23   org/springframework/boot/
        0  04-04-2019 02:23   org/springframework/boot/loader/
        0  04-04-2019 02:23   org/springframework/boot/loader/data/
        0  04-04-2019 02:23   org/springframework/boot/loader/jar/
        0  04-04-2019 02:23   org/springframework/boot/loader/archive/
        0  04-04-2019 02:23   org/springframework/boot/loader/util/
     2688  04-04-2019 02:23   org/springframework/boot/loader/data/RandomAccessDataFile$DataInputStream.class
     4976  04-04-2019 02:23   org/springframework/boot/loader/jar/AsciiBytes.class
      540  04-04-2019 02:23   org/springframework/boot/loader/jar/CentralDirectoryVisitor.class
     3263  04-04-2019 02:23   org/springframework/boot/loader/data/RandomAccessDataFile$FileAccess.class
     4015  04-04-2019 02:23   org/springframework/boot/loader/data/RandomAccessDataFile.class
      945  04-04-2019 02:23   org/springframework/boot/loader/archive/Archive.class
      282  04-04-2019 02:23   org/springframework/boot/loader/data/RandomAccessDataFile$1.class
     1593  04-04-2019 02:23   org/springframework/boot/loader/jar/JarFileEntries$1.class
      299  04-04-2019 02:23   org/springframework/boot/loader/jar/JarEntryFilter.class
      485  04-04-2019 02:23   org/springframework/boot/loader/data/RandomAccessData.class
      616  04-04-2019 02:23   org/springframework/boot/loader/jar/Bytes.class
      702  04-04-2019 02:23   org/springframework/boot/loader/jar/JarURLConnection$1.class
     9854  04-04-2019 02:23   org/springframework/boot/loader/jar/JarURLConnection.class
     1233  04-04-2019 02:23   org/springframework/boot/loader/jar/JarFile$2.class
     1487  04-04-2019 02:23   org/springframework/boot/loader/archive/ExplodedArchive$FileEntryIterator$EntryComparator.class
     3837  04-04-2019 02:23   org/springframework/boot/loader/archive/ExplodedArchive$FileEntryIterator.class
     1102  04-04-2019 02:23   org/springframework/boot/loader/archive/ExplodedArchive$FileEntry.class
      273  04-04-2019 02:23   org/springframework/boot/loader/archive/ExplodedArchive$1.class
     5243  04-04-2019 02:23   org/springframework/boot/loader/archive/ExplodedArchive.class
     1779  04-04-2019 02:23   org/springframework/boot/loader/archive/JarFileArchive$EntryIterator.class
     1081  04-04-2019 02:23   org/springframework/boot/loader/archive/JarFileArchive$JarFileEntry.class
     7336  04-04-2019 02:23   org/springframework/boot/loader/archive/JarFileArchive.class
    19737  04-04-2019 02:23   org/springframework/boot/loader/PropertiesLauncher.class
     1535  04-04-2019 02:23   org/springframework/boot/loader/LaunchedURLClassLoader$UseFastConnectionExceptionsEnumeration.class
     4306  04-04-2019 02:23   org/springframework/boot/loader/jar/JarURLConnection$JarEntryName.class
     5699  04-04-2019 02:23   org/springframework/boot/loader/LaunchedURLClassLoader.class
     1374  04-04-2019 02:23   org/springframework/boot/loader/jar/JarFile$JarFileType.class
     2062  04-04-2019 02:23   org/springframework/boot/loader/jar/JarFile$1.class
     2046  04-04-2019 02:23   org/springframework/boot/loader/jar/JarFileEntries$EntryIterator.class
    14010  04-04-2019 02:23   org/springframework/boot/loader/jar/JarFileEntries.class
     3116  04-04-2019 02:23   org/springframework/boot/loader/jar/CentralDirectoryEndRecord.class
     1813  04-04-2019 02:23   org/springframework/boot/loader/jar/ZipInflaterInputStream.class
      302  04-04-2019 02:23   org/springframework/boot/loader/archive/Archive$Entry.class
      437  04-04-2019 02:23   org/springframework/boot/loader/archive/Archive$EntryFilter.class
     3662  04-04-2019 02:23   org/springframework/boot/loader/jar/JarEntry.class
     5267  04-04-2019 02:23   org/springframework/boot/loader/jar/CentralDirectoryFileHeader.class
     4624  04-04-2019 02:23   org/springframework/boot/loader/jar/CentralDirectoryParser.class
    11548  04-04-2019 02:23   org/springframework/boot/loader/jar/Handler.class
     3650  04-04-2019 02:23   org/springframework/boot/loader/jar/StringSequence.class
      345  04-04-2019 02:23   org/springframework/boot/loader/jar/FileHeader.class
    15076  04-04-2019 02:23   org/springframework/boot/loader/jar/JarFile.class
     1953  04-04-2019 02:23   org/springframework/boot/loader/PropertiesLauncher$PrefixMatchingArchiveFilter.class
     1484  04-04-2019 02:23   org/springframework/boot/loader/PropertiesLauncher$ArchiveEntryFilter.class
      266  04-04-2019 02:23   org/springframework/boot/loader/PropertiesLauncher$1.class
     4684  04-04-2019 02:23   org/springframework/boot/loader/Launcher.class
     1502  04-04-2019 02:23   org/springframework/boot/loader/MainMethodRunner.class
     3608  04-04-2019 02:23   org/springframework/boot/loader/ExecutableArchiveLauncher.class
     1721  04-04-2019 02:23   org/springframework/boot/loader/WarLauncher.class
     1585  04-04-2019 02:23   org/springframework/boot/loader/JarLauncher.class
     5203  04-04-2019 02:23   org/springframework/boot/loader/util/SystemPropertyUtils.class
        0  07-15-2021 13:15   META-INF/
      288  07-15-2021 13:15   META-INF/MANIFEST.MF
        0  07-15-2021 13:15   BOOT-INF/
        0  07-15-2021 13:15   BOOT-INF/classes/
        0  07-15-2021 13:15   BOOT-INF/classes/com/
        0  07-15-2021 13:15   BOOT-INF/classes/com/example/
        0  07-15-2021 13:15   BOOT-INF/classes/com/example/so68382900/
      745  07-15-2021 13:15   BOOT-INF/classes/com/example/so68382900/DemoApplication.class
        1  07-15-2021 13:14   BOOT-INF/classes/application.properties
        0  07-15-2021 13:15   BOOT-INF/lib/
      398  07-15-2021 13:15   BOOT-INF/lib/spring-boot-starter-2.1.4.RELEASE.jar
  1262787  07-15-2021 13:15   BOOT-INF/lib/spring-boot-autoconfigure-2.1.4.RELEASE.jar
   952263  07-15-2021 13:15   BOOT-INF/lib/spring-boot-2.1.4.RELEASE.jar
      407  07-15-2021 13:15   BOOT-INF/lib/spring-boot-starter-logging-2.1.4.RELEASE.jar
    26586  06-26-2020 11:02   BOOT-INF/lib/javax.annotation-api-1.3.2.jar
  1099880  07-15-2021 13:15   BOOT-INF/lib/spring-context-5.1.6.RELEASE.jar
   369018  07-15-2021 13:15   BOOT-INF/lib/spring-aop-5.1.6.RELEASE.jar
   673302  07-15-2021 13:15   BOOT-INF/lib/spring-beans-5.1.6.RELEASE.jar
   280482  07-15-2021 13:15   BOOT-INF/lib/spring-expression-5.1.6.RELEASE.jar
  1293481  07-15-2021 13:15   BOOT-INF/lib/spring-core-5.1.6.RELEASE.jar
   301298  07-15-2021 13:15   BOOT-INF/lib/snakeyaml-1.23.jar
   290339  06-26-2020 11:01   BOOT-INF/lib/logback-classic-1.2.3.jar
    17522  07-15-2021 13:15   BOOT-INF/lib/log4j-to-slf4j-2.11.2.jar
     4589  07-15-2021 13:15   BOOT-INF/lib/jul-to-slf4j-1.7.26.jar
    23762  07-15-2021 13:15   BOOT-INF/lib/spring-jcl-5.1.6.RELEASE.jar
   471901  06-26-2020 11:01   BOOT-INF/lib/logback-core-1.2.3.jar
    41139  06-26-2020 11:01   BOOT-INF/lib/slf4j-api-1.7.26.jar
   266283  07-15-2021 13:15   BOOT-INF/lib/log4j-api-2.11.2.jar
---------                     -------
  7552715                     86 files
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement