gpt4 book ai didi

java - 尝试通过 gradle 将 zip 文件上传到本地 Artifact

转载 作者:行者123 更新时间:2023-12-03 05:23:31 24 4
gpt4 key购买 nike

我正在尝试结合 gradle 来熟悉 artifactory。我有一个测试项目,它基本上只包含一个 zip 文件(将上传到在 docker 中运行的本地 Artifact )和包装器 + build.gradle 文件的 gradlefiles。
我的 build.gradle 文件如下所示:

plugins {
id "com.jfrog.artifactory" version "4.16.0"
id 'maven-publish'
id 'java'
}

repositories {
maven { url 'http://localhost:8081/artifactory'}
}

configurations {
generic {
description = 'generic'
}
published
}

artifactory {
contextUrl = "http://localhost:8081/artifactory" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${local_user}"
password = "${local_pw}"
maven = true

}
defaults {
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team' : 'core']
publications('MyZip')
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${local_user}"
password = "${local_pw}"
maven = true

}
}
}
publishing {
publications{
MyZip(MavenPublication) {
artifact(file("jetty.zip")){
extension "zip"
}
}
}
}

artifactoryPublish {
publications('MyZip')
}
当我执行
./gradlew artifactoryPublish
它说“构建成功”,但只将构建信息上传到 Artifact ,而不是我希望它上传的 zip 文件。我用谷歌搜索并查看了以下内容:
https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenPublication.html
这篇文章中的 roma77 有完全相同的问题,但已修复,但对我没有用:
https://discuss.gradle.org/t/publish-zip-artifact/5792/2
我也试着按照这个例子 https://github.com/jfrog/project-examples/blob/master/gradle-examples/gradle-android-example/build.gradle
但这也没有用。
当我跑
./gradlew artifactoryPublish --info
它说
Task ':artifactoryPublish' is not up-to-date because:
Task has not declared any outputs despite executing actions.
好吧,这就是我问你们的重点,因为我几乎被卡住了^^ 任何帮助表示赞赏。

编辑1:
所以在@afterburner 提出了一个解决方案之后,我用这个 build.gradle 进行了尝试:
plugins {
id "com.jfrog.artifactory" version "4.16.0"
id 'maven-publish'
id 'java'
}


repositories {
maven { url 'http://localhost:8081/artifactory'}
}

configurations {
generic {
description = 'generic'
}
published
}

artifactory {
contextUrl = "http://localhost:8081/artifactory" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${local_user}"
password = "${local_pw}"
maven = true

}
defaults {
publishArtifacts = true
publications('myzip')
}
}
resolve {
repository {
repoKey = 'gradle-dev-local'
username = "${local_user}"
password = "${local_pw}"
maven = true

}
}
}

task makeZip(type: Zip) {
from fileTree(dir: 'jetty')
include '**/*'
archiveName "jetty.zip"
destinationDir file("$buildDir/libs/")
description "Assemble archive $archiveName into ${relativePath(destinationDir)}"
}

publishing {
publications{
myzip(MavenPublication) {
artifact makeZip
}
}
}

artifactoryPublish {
publications('myzip')
}
在下面我添加了一个如下所示的构建脚本:
buildscript {
repositories {
maven {
url 'http://localhost:8081/artifactory/plugins-release'
credentials {
username = "${local_user}"
password = "${local_pw}"
}
name = "local"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}
找到 here .它工作过一次,之后就不再工作了。它还在 gradle/unspecified 下上传了 zip 文件。请注意,我将我的 Gradle 技能描述为相当有限。我想我可能会错过一些基本配置,让 gradle 说出该怎么做。
日志:
> Task :artifactoryDeploys an incubating feature.
Deploying build descriptor to: http://localhost:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/gradle/1593782379748

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 2s
5 actionable tasks: 4 executed, 1 up-to-date

最佳答案

我让它与以下 build.gradle 一起工作:

buildscript {
repositories {
maven {
url 'http://localhost:8081/artifactory/gradle-dev'
credentials {
username = "${local_user}"
password = "${local_pw}"
}
name = "maven-main-cache"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
}
}

plugins {
id "com.jfrog.artifactory" version "4.16.0"
id 'maven-publish'
id 'java'
}

version = '0.1.0-SNAPSHOT'
group = 'io.klib'

repositories {
add buildscript.repositories.getByName("maven-main-cache")
}

artifactory {
contextUrl = "http://localhost:8081/artifactory" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${local_user}"
password = "${local_pw}"
maven = true

}
defaults {
publishArtifacts = true
publications('myzip')
}
}
resolve {
repository {
repoKey = 'gradle-dev-local'
username = "${local_user}"
password = "${local_pw}"
maven = true

}
}
}

task makeZip(type: Zip) {
from fileTree(dir: 'jetty')
include '**/*'
archiveName "jetty.zip"
destinationDir file("$buildDir/libs/")
description "Assemble archive $archiveName into ${relativePath(destinationDir)}"
}

publishing {
publications{
myzip(MavenPublication) {
artifact makeZip
}
}
}

artifactoryPublish {
publications('myzip')
}
makeZip 任务应该不是必需的,您可以直接添加文件。
我在这里犯了两个基本错误。首先,我完全错过了 buildscript 部分,这对于插件知道在哪里推送什么至关重要。其次,我错误地配置了 buildscript 部分。我想推送到“gradle-dev-local”repo,因为 artifactory 只允许你推送到本地存储库。在构建脚本中,我使用了“gradle-dev”虚拟存储库,因为那是包含“gradle-dev-local”的可访问虚拟存储库。 Virtual repositories include all local, remote and other virtual repositories.
我希望这可以帮助别人。

关于java - 尝试通过 gradle 将 zip 文件上传到本地 Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62643094/

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