gpt4 book ai didi

java - Spring Boot 使用 1.5.6 发布重新打包的子模块 jar

转载 作者:行者123 更新时间:2023-12-03 05:38:01 35 4
gpt4 key购买 nike

我们已经将一个 Maven 多模块项目转换为 gradle,并且在发布 Spring Boot jar 时遇到了问题。

设置是这样的

root
|- module1
|- common
|- common-test
|- module2-common
|- module2-write
|- module3-common
|- module3-write
|- module4
|- module5
|- deploy
deploy包含重新打包的 jar。

发布(使用 maven-publish)时,工件只有几千字节大。显然它实际上并没有发布 deploy jar 。

部署 build.gradle.kts
import org.flywaydb.gradle.task.FlywayMigrateTask
import org.springframework.boot.gradle.repackage.RepackageTask
import org.springframework.boot.gradle.run.BootRunTask

plugins {
kotlin("jvm")
id("org.springframework.boot") version ("1.5.6.RELEASE")
id("io.spring.dependency-management") version("1.0.6.RELEASE")
id("org.flywaydb.flyway")
java
}

tasks {
withType<Jar> {
baseName = project.name
version = project.version as String
}

val implementation = configurations.getByName("implementation")
configurations.create("includeAllJars") {
this.extendsFrom(implementation)
}
withType<RepackageTask> {
this.setCustomConfiguration("includeAllJars")
// this.classifier = "exec"
}
}


build.gradle.kts
plugins {
base
java
idea
kotlin("jvm") version "1.2.51"
kotlin("plugin.jpa") version ("1.2.51")
kotlin("plugin.spring") version ("1.2.51")
id("nebula.maven-publish") version "8.1.0"
...
}

allprojects {
group = "com.company.group"

ext {
set("springBootVersion", "1.5.6.RELEASE")
}
apply {
plugin("org.jetbrains.kotlin.jvm")
plugin("org.jetbrains.kotlin.plugin.jpa")
plugin("org.jetbrains.kotlin.plugin.spring")
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:${extra["springBootVersion"]}"))
...
}
}

val sourcesJar by tasks.registering(Jar::class) {
classifier = "sources"
from(sourceSets["main"].allSource)
}

publishing {
publications {
register("maven", MavenPublication::class) {
// from(project(":server-deploy").components["java"])
// artifact(sourcesJar.get())
// artifact(file("deploy/build/docker/runnable.jar"))
}
}
repositories {
...
}
}

对于出版物部分,我尝试指定 from(components["java"]) , artifact(file("deploy/build/libs/deploy-${project.version}.jar")) ,以及上述选项。所有结果都导致发布的 jar 文件只有 1-3KB 大。

我尝试将发布 block 移动到部署 build.gradle.kts ,但这会导致此错误
* What went wrong:
Execution failed for task ':deploy:publishMavenPublicationToMavenLocal'.
> Failed to publish publication 'maven' to repository 'mavenLocal'
> Invalid publication 'maven': POM file is invalid. Check any modifications you have made to the POM file.

The Spring Boot docs for the gradle plugin似乎没有列出任何关于此的内容。

最佳答案

关于 Wilkinson 先生的评论,Spring Boot 似乎不支持 Gradle 5 是完全正确的。解决方案是不使用 platform()在包含 spring boot 插件的一个模块中,但使用 platform()其他地方。这不是一个长期的解决方案!这在我们的例子中是完美的,因为我们直接从 Maven 过渡到 Gradle,然后立即从 Spring Boot 1 过渡到 Spring Boot 2。
deploy/build.gradle.kts

plugins {
id("org.springframework.boot") version ("1.5.6.RELEASE")
id("io.spring.dependency-management") version("1.0.6.RELEASE")
id("nebula.maven-publish")
java

}
dependencyManagement {
imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${extra["springBootVersion"]}") }
}

每隔 build.gradle.kts除了 deployroot
dependencies {
implementation(platform("org.springframework.boot:spring-boot-dependencies:${extra["springBootVersion"]}"))

}

关于java - Spring Boot 使用 1.5.6 发布重新打包的子模块 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54637853/

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