AbstractSpringJavaPlugin.groovy 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. /**
  31. * @author Rob Winch
  32. */
  33. public abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
  34. @Override
  35. public final void apply(Project project) {
  36. PluginManager pluginManager = project.getPluginManager();
  37. pluginManager.apply(JavaPlugin.class);
  38. pluginManager.apply(ManagementConfigurationPlugin.class);
  39. if (project.file("src/main/groovy").exists()
  40. || project.file("src/test/groovy").exists()
  41. || project.file("src/integration-test/groovy").exists()) {
  42. pluginManager.apply(GroovyPlugin.class);
  43. }
  44. pluginManager.apply("io.spring.convention.repository");
  45. pluginManager.apply(EclipseWtpPlugin);
  46. pluginManager.apply(IdeaPlugin);
  47. pluginManager.apply(PropDepsPlugin);
  48. pluginManager.apply(PropDepsEclipsePlugin);
  49. pluginManager.apply(PropDepsIdeaPlugin);
  50. project.getPlugins().withType(MavenPlugin) {
  51. pluginManager.apply(PropDepsMavenPlugin);
  52. }
  53. pluginManager.apply("io.spring.convention.tests-configuration");
  54. pluginManager.apply("io.spring.convention.integration-test");
  55. pluginManager.apply("io.spring.convention.springdependencymangement");
  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('com.github.ben-manes.versions');
  60. copyPropertyFromRootProjectTo("group", project);
  61. copyPropertyFromRootProjectTo("version", project);
  62. copyPropertyFromRootProjectTo("description", project);
  63. project.jar {
  64. manifest.attributes["Created-By"] =
  65. "${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})"
  66. manifest.attributes["Implementation-Title"] = project.name
  67. manifest.attributes["Implementation-Version"] = project.version
  68. manifest.attributes["Automatic-Module-Name"] = project.name.replace('-', '.')
  69. }
  70. additionalPlugins(project);
  71. }
  72. private void copyPropertyFromRootProjectTo(String propertyName, Project project) {
  73. Project rootProject = project.getRootProject();
  74. Object property = rootProject.findProperty(propertyName);
  75. if(property != null) {
  76. project.setProperty(propertyName, property);
  77. }
  78. }
  79. protected abstract void additionalPlugins(Project project);
  80. }