CheckstylePlugin.groovy 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 org.gradle.api.Plugin
  18. import org.gradle.api.Project
  19. import org.gradle.api.artifacts.VersionCatalogsExtension
  20. import org.gradle.api.plugins.JavaPlugin
  21. /**
  22. * Adds and configures Checkstyle plugin.
  23. *
  24. * @author Vedran Pavic
  25. */
  26. class CheckstylePlugin implements Plugin<Project> {
  27. final CHECKSTYLE_DIR = 'etc/checkstyle'
  28. @Override
  29. void apply(Project project) {
  30. def versionCatalog = project.rootProject.extensions.getByType(VersionCatalogsExtension.class)
  31. .named("libs")
  32. project.plugins.withType(JavaPlugin) {
  33. def checkstyleDir = project.rootProject.file(CHECKSTYLE_DIR)
  34. if (checkstyleDir.exists() && checkstyleDir.directory) {
  35. project.getPluginManager().apply('checkstyle')
  36. project.dependencies.add('checkstyle', versionCatalog.findLibrary('io-spring-javaformat-spring-javaformat-checkstyle').get())
  37. project.dependencies.add('checkstyle', versionCatalog.findLibrary('io-spring-nohttp-nohttp-checkstyle').get())
  38. project.checkstyle {
  39. configDirectory = checkstyleDir
  40. toolVersion = '8.21'
  41. }
  42. }
  43. }
  44. }
  45. }