gpt4 book ai didi

Gradle 未发布自定义 jar 工件

转载 作者:行者123 更新时间:2023-12-03 03:08:17 30 4
gpt4 key购买 nike

我有一个 gradle 构建,它必须将预构建的 jar 文件发布为工件。由于某种原因,它没有被拾取。这是重现它的简化版本:

文件夹内容:

settings.gradle
build.gradle
some.jar

设置.gradle:

rootProject.name = 'some'

build.gradle:

apply plugin: 'base'
apply plugin: 'maven-publish'

group = 'foo.bar'
version = '1.0'

task copyPrebuilt(type: Copy) {
from(projectDir) {
include 'some.jar'
rename 'some', "some-$version"
}
into distsDir
}

artifacts {
// should be 'archives'?
// http://stackoverflow.com/questions/39068090/gradle-archives-artifacts-not-populated-to-default-configuration
'default' (file("$distsDir/some-${version}.jar")) {
name 'some'
type 'jar'
builtBy copyPrebuilt
}
}

some-1.0.jar 没有被 gradle publishToMavenLocal 复制到 ~/.m2/repository/foo/bar/some/1.0

有什么线索吗?

最佳答案

发布内容的最简单方法是定义发布对象:

apply plugin: 'base'
apply plugin: 'maven-publish'

group = 'foo.bar'
version = '1.0'

task copyPrebuilt(type: Copy) {
from(projectDir) {
include 'some.jar'
rename 'some', "some-$version"
}
into buildDir
}

publishToMavenLocal.dependsOn copyPrebuilt

publishing {
publications {
prebuilt(MavenPublication) {
artifact file("$buildDir/some-${version}.jar")
}
}
}

此代码使 publishToMavenLocal 任务将 some-1.0.jar 安装到本地 maven 存储库。

关于Gradle 未发布自定义 jar 工件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41513548/

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