SpringDependencyManagementConventionPlugin.groovy 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2016-2019 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 io.spring.gradle.dependencymanagement.DependencyManagementPlugin
  18. import org.gradle.api.Plugin
  19. import org.gradle.api.Project
  20. /**
  21. * Adds and configures {@link DependencyManagementPlugin}.
  22. * <p>
  23. * Additionally, if 'gradle/dependency-management.gradle' file is present it will be
  24. * automatically applied file for configuring the dependencies.
  25. */
  26. class SpringDependencyManagementConventionPlugin implements Plugin<Project> {
  27. static final String DEPENDENCY_MANAGEMENT_RESOURCE = "gradle/dependency-management.gradle"
  28. @Override
  29. void apply(Project project) {
  30. project.getPluginManager().apply(ManagementConfigurationPlugin)
  31. project.getPluginManager().apply(DependencyManagementPlugin)
  32. project.dependencyManagement {
  33. resolutionStrategy {
  34. cacheChangingModulesFor 0, "seconds"
  35. }
  36. }
  37. File rootDir = project.rootDir
  38. List<File> dependencyManagementFiles = [project.rootProject.file(DEPENDENCY_MANAGEMENT_RESOURCE)]
  39. for (File dir = project.projectDir; dir != rootDir; dir = dir.parentFile) {
  40. dependencyManagementFiles.add(new File(dir, DEPENDENCY_MANAGEMENT_RESOURCE))
  41. }
  42. dependencyManagementFiles.each { f ->
  43. if (f.exists()) {
  44. project.apply from: f.absolutePath
  45. }
  46. }
  47. }
  48. }