使用 gradle 将不同的 jar 上传到 Artifactory

Uploading different jars to Artifactory with gradle

是否可以有条件地将 jar 上传到 artifactory?

我尝试过使用 Artifactory 插件,但如果只是从构建管道上传单个 jar,那效果很好。

如果我还想上传一个测试 jar,那怎么办?

我可以有一些配置来指定应该上传哪个 jar 吗?例如测试 jar 或 "normal" jar 文件

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

artifactory {
    clientConfig.setIncludeEnvVars(true)

    contextUrl = 'https://localhost:8081/artifactory/'
    publish {
        repository {
          repoKey = 'libs-release-local'
          username = "${artifactory_user}"
          password = "${artifactory_user_password}"
        }
        defaults {
           publications('mavenJava')
           publishArtifacts = true
           publishPom = true
           publishIvy = true
        }
     }
    resolve {
      contextUrl = 'https://localhost:8081/artifactory'
      repository {
        repoKey = 'libs-release-local'
        username = "${artifactory_user"
        password = "${artifactory_user_password}"
        maven = true
      }
    }
}

要从您的测试 SourceSet 发布 类(默认情况下 src/test/),您首先需要定义一个任务来创建 testJar:

task testJar(type: Jar) {
    classifier = 'tests'
    from sourceSets.test.output
}

然后将其添加到您的出版物中

publications {
    mavenJava(MavenPublication) {
      from components.java

        artifact testJar {
            classifier "test"
        }
    }
}

由于您已经从 artifactory 发布 publications('mavenJava'),因此您不必在那里进行任何更改。