本文介绍了使用 Gradle 将工件上传到 Artifactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Gradle 和 Artifactory 的新手,我想将 JAR 文件上传到 Artifactory.

I am a newbie to Gradle and Artifactory and I want to upload a JAR file to Artifactory.

这是我的 build.gradle 文件:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'artifactory-publish'

groupId = 'myGroup'
version = '1.0'
def artifactId = projectDir.name
def versionNumber = version

artifactory {
    contextUrl = 'http://path.to.artifactory' // base artifactory url
    publish {
        repository {
            repoKey = 'libs-releases'   // Artifactory repository key to publish to
            username = 'publisher'      // publisher user name
            password = '********'       // publisher password
            maven = true
        }
    }
}

artifactoryPublish {
    dependsOn jar
}

运行artifactoryPublish任务后,构建成功如下图:

After running the artifactoryPublish task, the build is successful as shown below:

> gradle artifactoryPublish  --stacktrace
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:artifactoryPublish
Deploying build info to: http://path.to.artifactory/api/build

BUILD SUCCESSFUL

Total time: 7.387 secs

但是,除了构建信息之外,没有任何内容发送到 Artifactory.

However, there is nothing sent to Artifactory except the build info.

任何帮助将不胜感激.

正如 JBaruch 提到的,我已经添加了

As JBaruch mentioned, I've added

apply plugin: 'maven-publish'

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

并将默认部分设置为人工任务

and defaults section to artifactory task

defaults {
   publications ('mavenJava')
}

现在可以了.

谢谢

推荐答案

那是因为您没有任何出版物.artifactory-publish 插件maven-publish 插件 并上传publications.

That's because you don't have any publications. The artifactory-publish plugin works with maven-publish plugin and uploads publications.

如果您更喜欢使用旧的 maven 插件,您需要 artifactory 插件,不是 artifactory-publish.

If you prefer working with the old maven plugin, you need artifactory plugin, not artifactory-publish.

查看概述部分使用 Gradle"页面官方文档.

这篇关于使用 Gradle 将工件上传到 Artifactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 00:33