【问题标题】:Uploading different jars to Artifactory with gradle使用 gradle 将不同的 jar 上传到 Artifactory
【发布时间】:2016-04-04 21:52:57
【问题描述】:

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

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

如果我也想上传一个测试jar,那该怎么做?

我可以有一些配置来指定应该上传哪个 jar 吗?例如测试 jar 或“正常”的 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
      }
    }
}

【问题讨论】:

  • 您使用的是哪个 maven 插件?较旧的maven 还是较新的maven-publish
  • 你链接到artifactory插件,我问的是maven插件。 Artifactory 插件使用 publicationspublishconfigs 取决于您使用的 maven 插件,以确定要发布的工件。如果您想发布其他工件(例如测试 jar),您只需添加一个新的 maven 发布或 publishconfig。我需要知道您正在使用哪个插件来给您适当的说明。分享您的 build.gradle 可能会有所帮助。
  • 感谢您的帮助,我现在已将 build.gradle 添加到我的问题中。我正在使用出版物

标签: plugins gradle artifactory


【解决方案1】:

要从您的测试 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'),因此您无需在此处进行任何更改。

【讨论】:

  • RaGe 太好了,非常感谢。我还有最后一个问题,是否可以有条件地进行上传?例如。如果有时我只想在某些情况下上传我的测试 jar
  • 我想你应该能够将artifact testJar{...} 包装在if (condition){...} 中,但我自己还没有测试过。
猜你喜欢
  • 1970-01-01
  • 2014-04-16
  • 1970-01-01
  • 2016-11-09
  • 1970-01-01
  • 2016-05-11
  • 1970-01-01
  • 2013-06-11
  • 2018-07-12
相关资源
最近更新 更多