简体   繁体   中英

How to create an executable Jar for Spring Boot using gradle in an offline environment

I want to create an executable Jar for Spring Boot using gradle in an offline environment. There is an error. Please tell me the solution.

■cmd

C: / ~ / ~ / demo gradlew bootJar --offline --stacktrace

FAILURE: Build failed with an excetion.

What went wrong:
Task 'bootJar' not found in root project 'demo'.

Exception is:
org.gradle.execution. TaskSelectionException: Task 'bootJar' not found in root project 'demo'.

......

■build.gradle

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

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

repositories {
    mavenCentral()
}

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

test {
    useJUnitPlatform()
}

■gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=gradle-6.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

■version

SpringBoot:2.4.2
gradle:6.6.1

The bootJar task comes from the Spring Boot Gradle plugin ( org.springframework.boot ). You've removed the plugin from the project therefore the bootJar task never gets created.

Gradle is smart enough to cache various parts of the build including dependencies and plugins. However, since you are getting that error, the Spring Boot plugin is not cached therefore you must go online temporarily in order for the plugin to be downloaded and cached.

If you're not able to temporarily go online, then for the bootJar task specifically, you must reimplement yourself in your project: https://github.com/spring-projects/spring-boot/blob/2.4.x/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM