2
0

AbstractSpringJavaPlugin.groovy 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2004-present 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.GroovyPlugin;
  20. import org.gradle.api.plugins.JavaPlugin
  21. import org.gradle.api.plugins.PluginManager;
  22. import org.gradle.plugins.ide.eclipse.EclipseWtpPlugin;
  23. import org.gradle.plugins.ide.idea.IdeaPlugin;
  24. import org.springframework.gradle.CopyPropertiesPlugin
  25. import org.springframework.gradle.propdeps.PropDepsEclipsePlugin
  26. import org.springframework.gradle.propdeps.PropDepsIdeaPlugin
  27. import org.springframework.gradle.propdeps.PropDepsPlugin;
  28. /**
  29. * @author Rob Winch
  30. */
  31. public abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
  32. @Override
  33. public final void apply(Project project) {
  34. PluginManager pluginManager = project.getPluginManager();
  35. pluginManager.apply(JavaPlugin.class);
  36. pluginManager.apply(ManagementConfigurationPlugin.class)
  37. if (project.file("src/main/groovy").exists()
  38. || project.file("src/test/groovy").exists()
  39. || project.file("src/integration-test/groovy").exists()) {
  40. pluginManager.apply(GroovyPlugin.class);
  41. }
  42. pluginManager.apply("io.spring.convention.repository");
  43. pluginManager.apply(EclipseWtpPlugin);
  44. pluginManager.apply(IdeaPlugin);
  45. pluginManager.apply(PropDepsPlugin);
  46. pluginManager.apply(PropDepsEclipsePlugin);
  47. pluginManager.apply(PropDepsIdeaPlugin);
  48. pluginManager.apply("io.spring.convention.tests-configuration");
  49. pluginManager.apply("io.spring.convention.integration-test");
  50. pluginManager.apply("io.spring.convention.javadoc-options");
  51. pluginManager.apply("io.spring.convention.checkstyle");
  52. pluginManager.apply(CopyPropertiesPlugin);
  53. pluginManager.apply("io.spring.convention.eclipse");
  54. project.jar {
  55. manifest.attributes["Created-By"] =
  56. "${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})"
  57. manifest.attributes["Implementation-Title"] = project.name
  58. manifest.attributes["Implementation-Version"] = project.version
  59. manifest.attributes["Automatic-Module-Name"] = project.name.replace('-', '.')
  60. }
  61. project.test {
  62. useJUnitPlatform()
  63. }
  64. additionalPlugins(project);
  65. }
  66. protected abstract void additionalPlugins(Project project);
  67. }