Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build doesn't add version to package

I'm creating a REST microservice using Spring Boot 2.0.0.M7 with Gradle 4.2. When I build from Eclipse or run from console ./gradlew build, the produced package in build/libs is named $app.jar instead of $app-$version.jar.

What am I missing? my build.gradle is the same as the Spring Boot Docker GS guide, and this problem prevent docker image to be built because the jar can't be found.

Here is my build.gradle file:

buildscript {
    ext {
        springBootVersion = '2.0.0.M7'
        springCloudVersion = 'Finchley.M5'
        gradleDockerVersion = '0.13.0'
    }
    repositories {
        mavenCentral()
        maven { url 'https://plugins.gradle.org/m2/' }
        maven { url 'https://repo.spring.io/snapshot' }
        maven { url 'https://repo.spring.io/milestone' }
        maven { url 'https://repo.spring.io/libs-milestone' }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("gradle.plugin.com.palantir.gradle.docker:gradle-docker:${gradleDockerVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

jar {
    baseName = 'networks'
    version = '0.9'
}

group = 'test'
sourceCompatibility = 1.8
targetCompatibility = 1.8

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

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'org.springframework.boot:spring-boot-starter-data-rest'
    compile 'org.springframework.boot:spring-boot-starter-json'
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'

    runtime 'org.springframework.boot:spring-boot-devtools'
    runtime 'org.postgresql:postgresql'

    testCompile 'org.springframework.boot:spring-boot-starter-test'
    testCompile 'junit:junit'
}

docker {
    name "${project.group}/${jar.baseName}"
    files jar.archivePath
    buildArgs(['JAR_FILE': "${jar.archiveName}"])
}
like image 334
HelLViS69 Avatar asked Oct 18 '22 01:10

HelLViS69


1 Answers

The version should be specified outside jar:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

version = "0.9"

jar {
    baseName = 'networks'
}
like image 108
Sync Avatar answered Oct 31 '22 12:10

Sync