使用gradle将jar上传到JFrog Artifactory

时间:2016-03-10 05:09:25

标签: 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中构建得很好,但我看不到任何内容上传。我错过了什么吗?

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

我可以上传jar。这就是我的build.gradle(app模块)的样子。另外,如果我在root 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'
}

答案 2 :(得分:0)

您需要插件:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.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()
}

人工配置:

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
相关问题