PageRenderTime 47ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/subprojects/ivy/src/integTest/groovy/org/gradle/api/publish/ivy/IvyPublishBasicIntegTest.groovy

https://github.com/gradle/gradle
Groovy | 390 lines | 340 code | 35 blank | 15 comment | 2 complexity | 9af463f0cf804d8300f55ab29affaf35 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. /*
  2. * Copyright 2013 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. package org.gradle.api.publish.ivy
  17. import org.gradle.integtests.fixtures.ToBeFixedForConfigurationCache
  18. import spock.lang.Issue
  19. class IvyPublishBasicIntegTest extends AbstractIvyPublishIntegTest {
  20. def "publishes nothing without defined publication"() {
  21. given:
  22. settingsFile << "rootProject.name = 'root'"
  23. buildFile << """
  24. apply plugin: 'ivy-publish'
  25. group = 'group'
  26. version = '1.0'
  27. publishing {
  28. repositories {
  29. ivy { url "${ivyRepo.uri}" }
  30. }
  31. }
  32. """
  33. when:
  34. succeeds 'publish'
  35. then:
  36. ivyRepo.module('group', 'root', '1.0').assertNotPublished()
  37. }
  38. @ToBeFixedForConfigurationCache
  39. def "publishes empty module when publication has no added component"() {
  40. given:
  41. settingsFile << "rootProject.name = 'empty-project'"
  42. buildFile << """
  43. apply plugin: 'ivy-publish'
  44. group = 'org.gradle.test'
  45. version = '1.0'
  46. publishing {
  47. repositories {
  48. ivy { url "${ivyRepo.uri}" }
  49. }
  50. publications {
  51. ivy(IvyPublication)
  52. }
  53. }
  54. """
  55. when:
  56. succeeds 'publish'
  57. then:
  58. def module = ivyRepo.module('org.gradle.test', 'empty-project', '1.0')
  59. module.assertPublished()
  60. module.assertArtifactsPublished("ivy-1.0.xml")
  61. and:
  62. with (module.parsedIvy) {
  63. configurations.isEmpty()
  64. artifacts.isEmpty()
  65. dependencies.isEmpty()
  66. status == "integration"
  67. }
  68. and:
  69. resolveArtifacts(module) {
  70. withoutModuleMetadata {
  71. expectFiles()
  72. }
  73. withModuleMetadata {
  74. noComponentPublished()
  75. }
  76. }
  77. }
  78. @ToBeFixedForConfigurationCache
  79. def "can publish simple jar"() {
  80. given:
  81. def javaLibrary = javaLibrary(ivyRepo.module('group', 'root', '1.0'))
  82. and:
  83. settingsFile << "rootProject.name = 'root'"
  84. buildFile << """
  85. apply plugin: 'ivy-publish'
  86. apply plugin: 'java'
  87. group = 'group'
  88. version = '1.0'
  89. publishing {
  90. repositories {
  91. ivy { url "${ivyRepo.uri}" }
  92. }
  93. publications {
  94. ivy(IvyPublication) {
  95. from components.java
  96. }
  97. }
  98. }
  99. """
  100. when:
  101. succeeds 'assemble'
  102. then: "jar is built but not published"
  103. javaLibrary.assertNotPublished()
  104. file('build/libs/root-1.0.jar').assertExists()
  105. when:
  106. succeeds 'publish'
  107. then: "jar is published to defined ivy repository"
  108. javaLibrary.assertPublishedAsJavaModule()
  109. javaLibrary.removeGradleMetadataRedirection()
  110. javaLibrary.parsedIvy.status == 'integration'
  111. javaLibrary.moduleDir.file('root-1.0.jar').assertIsCopyOf(file('build/libs/root-1.0.jar'))
  112. and:
  113. resolveArtifacts(javaLibrary) { expectFiles 'root-1.0.jar' }
  114. }
  115. def "reports failure publishing when model validation fails"() {
  116. given:
  117. settingsFile << "rootProject.name = 'bad-project'"
  118. buildFile << """
  119. apply plugin: 'ivy-publish'
  120. apply plugin: 'war'
  121. group = 'org.gradle.test'
  122. version = '1.0'
  123. publishing {
  124. repositories {
  125. ivy { url "${ivyRepo.uri}" }
  126. }
  127. publications {
  128. ivy(IvyPublication) {
  129. from components.java
  130. from components.web
  131. }
  132. }
  133. }
  134. """
  135. when:
  136. fails 'publish'
  137. then:
  138. failure.assertHasCause("Ivy publication 'ivy' cannot include multiple components")
  139. }
  140. @ToBeFixedForConfigurationCache
  141. def "publishes to all defined repositories"() {
  142. given:
  143. def ivyRepo2 = ivy("ivy-repo-2")
  144. settingsFile << "rootProject.name = 'root'"
  145. buildFile << """
  146. apply plugin: 'ivy-publish'
  147. group = 'org.gradle.test'
  148. version = '1.0'
  149. publishing {
  150. repositories {
  151. ivy { url "${ivyRepo.uri}" }
  152. ivy { url "${ivyRepo2.uri}" }
  153. }
  154. publications {
  155. ivy(IvyPublication)
  156. }
  157. }
  158. """
  159. when:
  160. succeeds 'publish'
  161. then:
  162. def module = ivyRepo.module('org.gradle.test', 'root', '1.0')
  163. module.assertPublished()
  164. def module2 = ivyRepo2.module('org.gradle.test', 'root', '1.0')
  165. module2.assertPublished()
  166. }
  167. @ToBeFixedForConfigurationCache
  168. def "can publish custom PublishArtifact"() {
  169. given:
  170. settingsFile << "rootProject.name = 'root'"
  171. buildFile << """
  172. apply plugin: 'ivy-publish'
  173. apply plugin: 'java'
  174. group = 'org.gradle.test'
  175. version = '1.0'
  176. def writeFileProvider = tasks.register("writeFile") {
  177. doLast {
  178. try (FileOutputStream out = new FileOutputStream("customArtifact.jar")) {}
  179. }
  180. }
  181. def customArtifact = new PublishArtifact() {
  182. @Override
  183. String getName() {
  184. return "customArtifact"
  185. }
  186. @Override
  187. String getExtension() {
  188. return "jar"
  189. }
  190. @Override
  191. String getType() {
  192. return "jar"
  193. }
  194. @Override
  195. String getClassifier() {
  196. return null
  197. }
  198. @Override
  199. File getFile() {
  200. return new File("customArtifact.jar")
  201. }
  202. @Override
  203. Date getDate() {
  204. return new Date()
  205. }
  206. @Override
  207. TaskDependency getBuildDependencies() {
  208. return new TaskDependency() {
  209. @Override
  210. Set<? extends Task> getDependencies(Task task) {
  211. return Collections.singleton(writeFileProvider.get())
  212. }
  213. }
  214. }
  215. }
  216. publishing {
  217. repositories {
  218. ivy { url "${ivyRepo.uri}" }
  219. }
  220. publications {
  221. ivy(IvyPublication) {
  222. artifact customArtifact
  223. }
  224. }
  225. }
  226. """
  227. when:
  228. succeeds 'publish'
  229. then:
  230. def module = ivyRepo.module('org.gradle.test', 'root', '1.0')
  231. module.assertPublished()
  232. }
  233. @ToBeFixedForConfigurationCache
  234. def "warns when trying to publish a transitive = false variant"() {
  235. given:
  236. def javaLibrary = javaLibrary(ivyRepo.module('group', 'root', '1.0'))
  237. and:
  238. settingsFile << "rootProject.name = 'root'"
  239. buildFile << """
  240. apply plugin: 'ivy-publish'
  241. apply plugin: 'java'
  242. group = 'group'
  243. version = '1.0'
  244. configurations {
  245. apiElements {
  246. transitive = false
  247. }
  248. runtimeElements {
  249. transitive = false
  250. }
  251. }
  252. publishing {
  253. repositories {
  254. ivy { url "${ivyRepo.uri}" }
  255. }
  256. publications {
  257. ivy(IvyPublication) {
  258. from components.java
  259. }
  260. }
  261. }
  262. """
  263. when:
  264. executer.withStackTraceChecksDisabled()
  265. succeeds 'publish'
  266. then: "build warned about transitive = true variant"
  267. outputContains("Publication ignores 'transitive = false' at configuration level.")
  268. }
  269. @ToBeFixedForConfigurationCache(because = "configuration cache doesn't support task failures")
  270. @Issue("https://github.com/gradle/gradle/issues/15009")
  271. def "fails publishing if a variant contains a dependency on an enforced platform"() {
  272. settingsFile << """
  273. rootProject.name = 'publish'
  274. """
  275. buildFile << """
  276. plugins {
  277. id 'java'
  278. id 'ivy-publish'
  279. }
  280. dependencies {
  281. implementation enforcedPlatform('org:platform:1.0')
  282. }
  283. publishing {
  284. repositories {
  285. ivy { url "${ivyRepo.uri}" }
  286. }
  287. publications {
  288. ivy(IvyPublication) {
  289. from components.java
  290. }
  291. }
  292. }
  293. """
  294. when:
  295. fails ':publish'
  296. then:
  297. failure.assertHasCause """Invalid publication 'ivy':
  298. - Variant 'runtimeElements' contains a dependency on enforced platform 'org:platform'
  299. In general publishing dependencies to enforced platforms is a mistake: enforced platforms shouldn't be used for published components because they behave like forced dependencies and leak to consumers. This can result in hard to diagnose dependency resolution errors. If you did this intentionally you can disable this check by adding 'enforced-platform' to the suppressed validations of the :generateMetadataFileForIvyPublication task."""
  300. }
  301. @Issue("https://github.com/gradle/gradle/issues/15009")
  302. @ToBeFixedForConfigurationCache(because = "configuration cache doesn't support task failures")
  303. def "can disable validation of publication of dependencies on enforced platforms"() {
  304. settingsFile << """
  305. rootProject.name = 'publish'
  306. """
  307. buildFile << """
  308. plugins {
  309. id 'java'
  310. id 'ivy-publish'
  311. }
  312. group = 'com.acme'
  313. version = '0.999'
  314. dependencies {
  315. implementation enforcedPlatform('org:platform:1.0')
  316. }
  317. publishing {
  318. repositories {
  319. ivy { url "${ivyRepo.uri}" }
  320. }
  321. publications {
  322. ivy(IvyPublication) {
  323. from components.java
  324. }
  325. }
  326. }
  327. tasks.named('generateMetadataFileForIvyPublication') {
  328. suppressedValidationErrors.add('enforced-platform')
  329. }
  330. """
  331. when:
  332. succeeds ':publish'
  333. then:
  334. executedAndNotSkipped ':generateMetadataFileForIvyPublication', ':publishIvyPublicationToIvyRepository'
  335. }
  336. }