使用 gradle 在 artifactory 中发布最终的 jar 文件

publish final jar file in artifactory using gradle

我正在尝试将 jar 文件(gradle 项目的输出)发布到 jfrog/artifactory。当我执行gradlew buildgradlew build artifactoryPublish时项目成功。我还在控制台上看到 Build successfully deployed. Browse it in Artifactory under https://... 但是当我去 Artifactory 时什么也没有。我尝试遵循 jfrog/artifactory documentation, some questions on Whosebug like this one and this one。以下是我 build.gradle

的片段
 buildscript {
    repositories {
        jcenter()
        
    }
    dependencies {
        //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
    }
}

plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}


apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'io.spring.dependency-management'

allprojects {
    apply plugin: "com.jfrog.artifactory"   
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:29.0-jre'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.13'
}

task sourceJar(type: Jar){
    from file("build/libs/mygradle-1.0.0-sources.jar")
    classifier = 'sources'
}

task certify(type: Zip, group: 'build', dependsOn: 'build') {
    from ("build.gradle")
    from ("libs") 
    from ("src/test")
    from ("build/libs")
    from ("${buildDir}/reports/tests")
    archiveFileName = "certify-resources.zip"
    destinationDirectory = file("${buildDir}/certify")
}

version  = '1.0.0'
group = 'com.mypro.test'                // this is the package prefix the jar will go into artifactory

artifacts {
    archives sourceJar
}

publishing {
    publications {
        pluginJar(MavenPublication) {
            groupId "${group}"
            artifactId 'mygradle'                         // this is the package suffix the jar will go into in artifactory
            version "${version}"
            artifact sourceJar
            from components.java
        }
    }
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'gradle-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            
        }
    }
    resolve {
        repository {
            repoKey = 'gradle-dev'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            
        }
    }
}

我不确定我错过了什么。谁能建议我错过了什么。谢谢

编辑:我创建了 rhel/artifactory 的新实例和一个新的 gradle 项目,只是为了确保问题不是来自其他地方,而是

仅此信息 Build-info 已成功部署。当我用

执行 gradlew build artifactoryPublish 时,在 Artifactory under http://100.100.11.11:8081/artifactory/webapp/builds/mygradle/1675035714284 中浏览它

BUILD SUCCESSFUL

可以从 components.java 中提取 JAR 组件。

尝试将其添加到发布中,如下所示:

pluginJar(MavenPublication) {
    groupId "${group}"
    artifactId 'my-published-project'
    version "${version}"
    artifact sourceJar

    from components.java // <- add this line
}

the java component in its default setup consists of a JAR — produced by the jar task

有关详细信息,请参阅 Component terminology and Maven publications

编辑: 此外,由于“pluginJar”不是默认发布名称,我们应该将发布添加到列表中(插件默认添加 mavenJava 和 ivyJava)。

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'gradle-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            
        }
        defaults {
            publications('pluginJar') // <- add this
        }
    }
...
}