使用 gradle 将 jar 上传到 JFrog Artifactory

Upload jar to JFrog Artifactory using gradle

我想将我的项目 (Android Studio) 中的一个 jar 上传到 JFrog Artifactory。我浏览了几个链接,最后我这样做了,

apply plugin : 'maven'
configurations {
resultArchives
}

uploadResultArchives {
repositories {
    mavenDeployer {
        repository(url: "http://artifactory/libs-release-local/")
                {
                    authentication(userName: 'a', password: 'pass');
                }

    }
}}

artifacts{
resultArchives file: file('gradle/plugin-1.0.0.jar')
}

这在 gradle 中构建良好,但我没有看到任何内容上传。我错过了什么吗?

请使用Gradle Artifactory plugin。它负责上传并使用构建元数据注释工件。

JFrog GitHub repo 包含大量关于如何配置插件的示例。

我可以上传 jar。这就是我的 build.gradle(应用程序模块)看起来 like.Also 的样子,如果我在根 build.gradle 中编写代码(这是我检查过的帖子建议的,我得到一个错误,未指定 buildToolsversion )

apply plugin: 'com.android.application
apply plugin: 'maven'
apply plugin: 'project-reports'
apply plugin: 'maven-publish
apply plugin: 'com.jfrog.artifactory'

GroupId = "grp Id"
version = 1.0.0


buildscript {
repositories {
    jcenter()
    maven {
        url 'https://plugins.gradle.org/m2/'
    }
}
dependencies {
    classpath 'com.gradle.publish:plugin-publish-plugin:0.9.3'
}
}
apply plugin:'maven'

publishing {
publications {
    mavenJava(MavenPublication) {
    //    from components.java
        artifact file("path/plugin.jar")
      }
  }
 }
allprojects {
apply plugin: "com.jfrog.artifactory"
}
  artifactory {
    contextUrl = "http://artifactory"
  publish {
    repository {
        repoKey = 'libs-snapshot-local'
        username = "unam"
        password = "pass"
        maven = true

    }
    defaults{
        publications ('mavenJava')
        publishArtifacts = true
        }
     }
   }

  repositories {
   maven {
    url 'http://artifactory/libs-release-local/'
    credentials {
        username = "uname"
        password = "pass"
    }
   }

   }


  android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
    applicationId "com.vitalconnect.artifactory_demo"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),             'proguard-rules.pro'
       }
    }  
  }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
}

您需要插件:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'

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

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()
}

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

        }
    }
}

以及发布:

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

gradle.properties

artifactory_user=publisher
artifactory_password=*****
artifactory_contextUrl=http://IP:PORT/artifactory

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

gradle artifactoryPublish