代码之家  ›  专栏  ›  技术社区  ›  tuncaysenturk

使用Gradle将工件上载到Artifacty

  •  93
  • tuncaysenturk  · 技术社区  · 11 年前

    我是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
    }
    

    运行 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
    

    然而,除了构建信息之外,没有任何东西发送给Artifacty。

    任何帮助都将不胜感激。

    编辑:

    正如JBaruch所提到的,我添加了以下内容:

    apply plugin: 'maven-publish'
    
    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java
            }
        }
    }
    

    并将节默认为artifactory任务:

    defaults {
       publications ('mavenJava')
    }
    

    现在它起作用了。

    谢谢

    5 回复  |  直到 3 年前
        1
  •  60
  •   Daniel A.A. Pelsmaeker    10 年前

    那是因为你没有 publications 这个 artifactory-publish plugin 与一起工作 maven-publish plugin 和上载 publications .

    如果您喜欢与 the old maven plugin ,你需要 artifactory plugin 艺术作品出版 .

    看看 Overview part in "Working with Gradle" page 官方文件中。

        2
  •  11
  •   nyg    9 年前

    我把这件事做好了。我实际上使用的是一个已经创建的jar,所以我使用下面的代码来指定要上传的jar:

    publishing {
        publications {
            mavenJava(MavenPublication) {
                // from components.java
                artifact file("path/jar-1.0.0.jar")
            }
        }
    }
    
        3
  •  9
  •   grep    6 年前

    您需要插件:

    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 {
        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
            }
        }
    }
    

    梯度.属性

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

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

    gradle artifactoryPublish
    
        4
  •  6
  •   gary69    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
            }
        }
    }
    
        5
  •  0
  •   Mahozad    3 年前

    我就是这样做的 Kotlin DSL (build.gradle.kts)用于 my Android library :

    plugins {
        id("maven-publish")
        // ...
    }
    
    lateinit var sourcesArtifact: PublishArtifact
    lateinit var javadocArtifact: PublishArtifact
    tasks {
        val sourcesJar by creating(Jar::class) {
            archiveClassifier.set("sources")
            from(android.sourceSets["main"].java.srcDirs)
        }
    
        val dokkaHtml by getting(org.jetbrains.dokka.gradle.DokkaTask::class)
    
        val javadocJar by creating(Jar::class) {
            dependsOn(dokkaHtml)
            archiveClassifier.set("javadoc")
            from(dokkaHtml.outputDirectory)
        }
    
        artifacts {
            sourcesArtifact = archives(sourcesJar)
            javadocArtifact = archives(javadocJar)
        }
    }
    
    afterEvaluate {
        publishing {
            repositories {
                maven {
                    name = "GitHubPackages"
                    url = uri("https://maven.pkg.github.com/mahozad/android-pie-chart")
                    credentials {
                        username = project.properties["github.username"] as String? ?: System.getenv("GITHUB_ACTOR") ?: ""
                        password = project.properties["github.token"] as String? ?: System.getenv("GITHUB_TOKEN") ?: ""
                    }
                }
            }
            publications {
                create<MavenPublication>("Release") {
                    // Applies the component for the release build variant (two artifacts: the aar and the sources)
                    from(components["release"])
                    artifact(sourcesArtifact)
                    artifact(javadocArtifact)
                }
            }
        }
    }