CheckstylePlugin.groovy 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.plugins.JavaPlugin
  20. /**
  21. * Adds and configures Checkstyle plugin.
  22. *
  23. * @author Vedran Pavic
  24. */
  25. class CheckstylePlugin implements Plugin<Project> {
  26. final CHECKSTYLE_DIR = 'etc/checkstyle'
  27. @Override
  28. void apply(Project project) {
  29. project.plugins.withType(JavaPlugin) {
  30. def checkstyleDir = project.rootProject.file(CHECKSTYLE_DIR)
  31. if (checkstyleDir.exists() && checkstyleDir.directory) {
  32. project.getPluginManager().apply('checkstyle')
  33. project.dependencies.add('checkstyle', 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.15')
  34. project.dependencies.add('checkstyle', 'io.spring.nohttp:nohttp-checkstyle:0.0.11')
  35. project.checkstyle {
  36. configDirectory = checkstyleDir
  37. toolVersion = '8.21'
  38. }
  39. }
  40. }
  41. }
  42. }