使用Gradle将工件上载到Artifactory

tun*_*urk 73 publish artifactory gradle

我是Gradle和Artifactory的新手,我想将一个JAR文件上传到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
}
Run Code Online (Sandbox Code Playgroud)

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

> 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
Run Code Online (Sandbox Code Playgroud)

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

任何帮助都感激不尽.

编辑:

正如JBaruch所说,我补充道

apply plugin: 'maven-publish'

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和默认部分到神器任务

defaults {
   publications ('mavenJava')
}
Run Code Online (Sandbox Code Playgroud)

现在它有效.

谢谢

JBa*_*uch 49

那是因为你没有publications.该artifactory-publish插件适用于maven-publish插件和上传publications.

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

请查看官方文档的"使用Gradle"页面中的Overview部分.

  • 我希望来自神器的人来...因为在文档中没有提到`maven-publish`.感谢@JBaruch的帮助!http://www.jfrog.com/confluence/display/RTF/Gradle+1.6+Publishing+Artifactory+Plugin (7认同)
  • 嗨JBrauch感谢您的回复.我已经在帖子中添加了缺少的部分,以帮助其他人遇到同样的问题. (5认同)
  • @JBaruch仍然没有两个链接页面提到"maven-publish".我同意@Ryan认为这会有所帮助.但是感谢这里的答案 (5认同)

gre*_*rep 8

你需要插件:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
Run Code Online (Sandbox Code Playgroud)

构建项目并从 artifactory 中检索 jars:

buildscript {
    repositories {
        maven {
            url 'http://[IP]:[PORT]/artifactory/gradle-dev'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }
        mavenCentral()
    }
    dependencies { classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.5.4" }
}

repositories {
    mavenCentral()
    mavenLocal()
}
Run Code Online (Sandbox Code Playgroud)

Artifactory 配置:

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = 'gradle-dev-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
        }
        defaults {
            publications('mavenJava')
        }
        publishBuildInfo = true
        publishArtifacts = true
        publishPom = true
    }
    resolve {
        repository {
            repoKey = 'gradle-dev'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和出版:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

gradle.properties

artifactory_user=publisher
artifactory_password=*****
artifactory_contextUrl=http://IP:PORT/artifactory
Run Code Online (Sandbox Code Playgroud)

所以一切都很简单。如果你想上传你的jar:

gradle artifactoryPublish
Run Code Online (Sandbox Code Playgroud)


sve*_*ver 7

我得到了这个工作.我实际上是在使用已经创建的jar,所以我使用下面的代码来指定要上传的jar:

publishing {
    publications {
        mavenJava(MavenPublication) {
            // from components.java
            artifact file("path/jar-1.0.0.jar")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


gar*_*y69 6

这就是对我有用的命令 gradle clean build publish

apply plugin: 'maven-publish'
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'maven'

group = 'com.mine'
version = '1.0.1-SNAPSHOT'

repositories{
    mavenCentral()
}

dependencies {
    compile gradleApi()
    compile localGroovy()
    compile 'com.google.guava:guava:27.0-jre'
    testCompile 'junit:junit:4.12'
    //compile 'org.apache.commons:commons-lang3:3.8.1'
}

publishing {
    repositories {
        maven {
            url = 'https://artifactory.mine.net/artifactory/my-snapshots-maven'
            credentials {
                username 'user'
                password 'password'
            }
        }
    }
    publications{
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}
Run Code Online (Sandbox Code Playgroud)