RepositoryConventionPlugin.groovy 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2016-2018 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * https://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, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package io.spring.gradle.convention;
  17. import org.gradle.api.Plugin
  18. import org.gradle.api.Project
  19. class RepositoryConventionPlugin implements Plugin<Project> {
  20. @Override
  21. void apply(Project project) {
  22. String[] forceMavenRepositories = ((String) project.findProperty("forceMavenRepositories"))?.split(',')
  23. boolean isImplicitSnapshotRepository = forceMavenRepositories == null && Utils.isSnapshot(project)
  24. boolean isImplicitMilestoneRepository = forceMavenRepositories == null && Utils.isMilestone(project)
  25. boolean isSnapshot = isImplicitSnapshotRepository || forceMavenRepositories?.contains('snapshot')
  26. boolean isMilestone = isImplicitMilestoneRepository || forceMavenRepositories?.contains('milestone')
  27. project.repositories {
  28. if (forceMavenRepositories?.contains('local')) {
  29. mavenLocal()
  30. }
  31. mavenCentral()
  32. jcenter() {
  33. content {
  34. includeGroup "org.gretty"
  35. }
  36. }
  37. if (isSnapshot) {
  38. maven {
  39. name = 'artifactory-snapshot'
  40. if (project.hasProperty('artifactoryUsername')) {
  41. credentials {
  42. username project.artifactoryUsername
  43. password project.artifactoryPassword
  44. }
  45. }
  46. url = 'https://repo.spring.io/snapshot/'
  47. }
  48. }
  49. if (isSnapshot || isMilestone) {
  50. maven {
  51. name = 'artifactory-milestone'
  52. if (project.hasProperty('artifactoryUsername')) {
  53. credentials {
  54. username project.artifactoryUsername
  55. password project.artifactoryPassword
  56. }
  57. }
  58. url = 'https://repo.spring.io/milestone/'
  59. }
  60. }
  61. maven {
  62. name = 'artifactory-release'
  63. if (project.hasProperty('artifactoryUsername')) {
  64. credentials {
  65. username project.artifactoryUsername
  66. password project.artifactoryPassword
  67. }
  68. }
  69. url = 'https://repo.spring.io/release/'
  70. }
  71. maven {
  72. name = 'shibboleth'
  73. url = 'https://build.shibboleth.net/nexus/content/repositories/releases/'
  74. }
  75. }
  76. }
  77. }