gpt4 book ai didi

gradle - BootJar + MavenJar。工件不是由这个构建产生的

转载 作者:行者123 更新时间:2023-12-03 02:42:06 25 4
gpt4 key购买 nike

我有一个具有以下层次结构的示例项目:

Sample (root)
-- model (simple jar)
-- api (springboot jar)

我想将两个生成的 jars:plain jar & bootJar 发布到我的 localRepository。
gradlew clean build -xTest publishToMavenLocal    

但是,会出现以下错误:
* What went wrong:
Execution failed for task ':api:publishMavenJavaPublicationToMavenLocal'.
> Failed to publish publication 'mavenJava' to repository 'mavenLocal'
> Artifact api.jar wasn't produced by this build.

根 build.gradle 如下:
plugins {
id 'java'
id "org.springframework.boot" version "2.2.5.RELEASE" apply false
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
}
group 'sample'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}
ext {
artifactVersion = version
springBootVersion = "2.2.5.RELEASE"
}

allprojects {
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
jcenter()
}
}

subprojects {
apply plugin: "io.spring.dependency-management"
apply plugin: "maven-publish"

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
dependencies {
implementation "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}

publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.name
version project.version

from components.java
}
}
}
}

api build.gradle
apply plugin: 'org.springframework.boot'

dependencies {
compile project(":model")
implementation "org.springframework.boot:spring-boot-starter-web"
}

bootJar {
}

将 bootJava 任务添加到 api build.gradle 允许直接从 api 模块发布 bootJar,但根发布任务仍然中断。
publishing {
publications {
bootJava(MavenPublication) {
artifact bootJar
}
}
}

我已经尝试了几乎所有来自 docs 和 google 的解决方案,但似乎都没有奏效。
谁能解释一下,什么是错误配置?

Gradle 版本:6.3

最佳答案

如 gradle 文档 here 所述:

Starting from Gradle 6.2, Gradle performs a sanity check before uploading, to make sure you don’t upload stale files (files produced by another build). This introduces a problem with Spring Boot applications which are uploaded using the components.java component



更多解释可在上面的链接中找到。
他们提出了以下我个人尝试并为我工作的解决方法:

配置传出配置
configurations {
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
it.outgoing.artifact(bootJar)
}
}

在我的 build.gradle 配置之后:
....
apply plugin: 'maven-publish'
...

configurations {
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
it.outgoing.artifact(bootJar)
}
....
}


publishing {
publications {
myPublication(MavenPublication) {
groupId groupId
artifactId artifactId
version version
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
repositories {
maven {
url azureRepoUrl
name azureRepoName
credentials {
username azureRepoUserName
password azureRepoAccessToken
}
}
}
}

关于gradle - BootJar + MavenJar。工件不是由这个构建产生的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61197984/

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