【问题标题】:Upload jar to JFrog Artifactory using gradle使用 gradle 将 jar 上传到 JFrog Artifactory
【发布时间】:2016-03-10 05:09:24
【问题描述】:

我想将我的项目 (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 中构建良好,但我没有看到任何上传。我错过了什么吗?

【问题讨论】:

    标签: maven gradle jar artifactory publishing


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      你需要插件:

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-04-16
          • 2016-11-09
          • 1970-01-01
          • 1970-01-01
          • 2017-09-29
          相关资源
          最近更新 更多