简体   繁体   中英

Build executable .jar from spring boot 1.5.3 with gradle

I have a spring boot project (1.5.3 release) and using gradle 4.4. I'll build a .jar executable for install a service on linux server. but I'm having problems generating the executable .jar file.

  buildscript {
    ext {
        springBootVersion = '1.5.8.RELEASE'
        //springBootVersion = '2.0.3.RELEASE'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'

springBoot {
    executable = true
}

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

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile("org.springframework.boot:spring-boot-starter-web")
    compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4')
    compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.371'
    compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.370'
    runtime('org.springframework.boot:spring-boot-devtools')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
    testCompile('com.jayway.jsonpath:json-path')

}

How i can generate the .jar?

There missing dependency for boot jar.

add this in build.gradle:

bootJar {
    baseName = 'application-name'
    version =  '1.0.0'
}

command in terminal:

gradle bootjar

you can try this:

plugins {
id 'java'
id "maven-publish"
}
publishing {
publications {
    maven(MavenPublication) {
        groupId = 'com.your.project'
        version = '0.0.1-SNAPSHOT'
        from components.java
    }
  }
}

repositories {
   mavenCentral()
 }

and run command

gradle publishToMavenLocal

jar file will be generated in local maven repository.

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