AbstractSpringJavaPlugin.groovy 3.0 KB

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