gpt4 book ai didi

spring - Gradle 构建不会向包添加版本

转载 作者:行者123 更新时间:2023-12-03 09:35:21 27 4
gpt4 key购买 nike

我正在使用 Spring Boot 2.0.0.M7 创建一个 REST 微服务与 Gradle 4.2 .
当我从 Eclipse 构建或从控制台运行时 ./gradlew build ,生成的包在build/libs被命名 $app.jar而不是 $app-$version.jar .

我错过了什么?我的 build.gradle 与 Spring Boot Docker GS 相同指南,这个问题阻止了 docker 镜像的构建,因为找不到 jar。

这是我的 build.gradle 文件:

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}"])
}

最佳答案

版本应该在 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'
}

关于spring - Gradle 构建不会向包添加版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47924697/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com