publish.gradle 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright 2015 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // Source: https://github.com/ratpack/ratpack/blob/master/gradle/publish.gradle
  17. apply plugin: "maven"
  18. apply plugin: "com.jfrog.artifactory"
  19. apply plugin: 'com.jfrog.bintray'
  20. afterEvaluate {
  21. assert description: "Project $project.path is published, must have a description"
  22. }
  23. tasks.withType(Upload).matching { it.name != "install" }.configureEach {
  24. rootProject.subprojects {
  25. mustRunAfter tasks.matching { it instanceof VerificationTask }
  26. }
  27. }
  28. def isRoot = project.rootProject == project
  29. if (!isRoot) {
  30. apply from: "$rootDir/gradle/version.gradle"
  31. apply from: "${rootDir}/gradle/pom.gradle"
  32. configurations {
  33. configurations {
  34. all {
  35. incoming.afterResolve {
  36. dependencies.withType(ModuleDependency) { dep ->
  37. excludeRules.each {
  38. if ([it.group, it.module].any { it == null }) {
  39. throw new InvalidUserDataException(
  40. "Partial exclude for dependency '$dep.group:$dep.name:$dep.version' of $project: [group: $it.group, module: $it.module]\n\nExcludes must specify both group and module and neither can be '*'."
  41. )
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50. def isSnapshot = version.endsWith("-SNAPSHOT")
  51. def isCIandTagged = System.getenv("CIRCLE_TAG") != null
  52. // define in ~/.gradle/gradle.properties to override for testing
  53. def forceLocal = project.hasProperty('forceLocal') && forceLocal
  54. artifactoryPublish { task ->
  55. gradle.taskGraph.whenReady { taskGraph ->
  56. def startParameter = project.gradle.startParameter
  57. if (taskGraph.hasTask(task) && startParameter.parallelProjectExecutionEnabled && startParameter.maxWorkerCount > 1) {
  58. throw new IllegalStateException("cannot run " + task + " with --parallel and --max-workers > 1")
  59. }
  60. }
  61. }
  62. artifactory {
  63. gradle.taskGraph.whenReady { taskGraph ->
  64. if (taskGraph.hasTask(artifactoryPublish)) {
  65. assert !project.hasProperty("removeJarVersionNumbers") || !removeJarVersionNumbers
  66. // trigger error if missing
  67. bintrayUser
  68. bintrayApiKey
  69. }
  70. }
  71. publish {
  72. contextUrl = forceLocal ? 'http://localhost:8080/artifactory' : 'https://oss.jfrog.org'
  73. repository {
  74. if (forceLocal)
  75. repoKey = isSnapshot ? 'libs-snapshot-local' : 'libs-release-local'
  76. else
  77. repoKey = isSnapshot ? 'oss-snapshot-local' : 'oss-release-local'
  78. if (project.hasProperty("bintrayUser") && project.hasProperty("bintrayApiKey")) {
  79. username = bintrayUser
  80. password = bintrayApiKey
  81. }
  82. }
  83. defaults {
  84. if (!isRoot) publishConfigs('archives')
  85. publishIvy = false // This isn't supported by bintray anyway.
  86. }
  87. }
  88. }
  89. bintrayUpload { task ->
  90. gradle.taskGraph.whenReady { taskGraph ->
  91. def startParameter = project.gradle.startParameter
  92. if (taskGraph.hasTask(task) && startParameter.parallelProjectExecutionEnabled && startParameter.maxWorkerCount > 1) {
  93. throw new IllegalStateException("cannot run " + task + " with --parallel and --max-workers > 1")
  94. }
  95. }
  96. }
  97. bintray {
  98. gradle.taskGraph.whenReady { taskGraph ->
  99. if (taskGraph.hasTask(bintrayUpload)) {
  100. assert !project.hasProperty("removeJarVersionNumbers") || !removeJarVersionNumbers
  101. // trigger error if missing
  102. bintrayUser
  103. bintrayApiKey
  104. }
  105. }
  106. if (project.hasProperty("bintrayUser") && project.hasProperty("bintrayApiKey")) {
  107. user = bintrayUser
  108. key = bintrayApiKey
  109. }
  110. if (!isRoot) configurations = ['archives']
  111. // dryRun = true //[Default: false] Whether to run this as dry-run, without deploying
  112. publish = true //[Default: false] Whether version should be auto published after an upload
  113. // override = true //[Default: false] Whether to override version artifacts already published
  114. //Package configuration. The plugin will use the repo and name properties to check if the package already exists. In that case, there's no need to configure the other package properties (like userOrg, desc, etc).
  115. pkg {
  116. repo = 'datadog-maven'
  117. name = 'dd-trace-java'
  118. userOrg = 'datadog' //An optional organization name when the repo belongs to one of the user's orgs
  119. desc = 'Client libraries for Datadog APM'
  120. websiteUrl = 'https://github.com/datadog/dd-trace-java'
  121. issueTrackerUrl = 'https://github.com/datadog/dd-trace-java/issues'
  122. vcsUrl = 'https://github.com/datadog/dd-trace-java.git'
  123. licenses = ['Apache-2.0']
  124. githubRepo = 'datadog/dd-trace-java' //Optional Github repository
  125. githubReleaseNotesFile = 'README.md' //Optional Github readme file
  126. }
  127. }
  128. if (!isSnapshot && isCIandTagged) {
  129. artifactoryPublish.finalizedBy bintrayUpload
  130. }