EclipsePlugin.groovy 2.5 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.plugins.ide.eclipse.EclipsePlugin
  20. /**
  21. * Plugin to tweak .classpath settings so that eclipse/sts/vscode can
  22. * be imported cleanly.
  23. *
  24. * @author Janne Valkealahti
  25. */
  26. class EclipsePlugin implements Plugin<Project> {
  27. @Override
  28. void apply(Project project) {
  29. project.plugins.apply(EclipsePlugin)
  30. project.eclipse {
  31. classpath {
  32. file {
  33. whenMerged {
  34. // for aspects gradle eclipse integration wrongly creates lib entries for
  35. // aspects/build/classes/java/main and aspects/build/resources/main which
  36. // never has anything. eclipse/sts don't care, vscode language server
  37. // complains about missing folders. So remove those from a .classpath
  38. entries.removeAll {
  39. entry -> entry.kind == 'lib' && (entry.path.contains('aspects/build/classes/java/main') || entry.path.contains('aspects/build/resources/main'))
  40. }
  41. // there are cycles and then dependencies between projects main sources and
  42. // test sources. Looks like gradle eclipse integration is getting confused.
  43. // thus just relax rules so that projects always sees everything from
  44. // dependant project.
  45. entries
  46. .findAll { entry -> entry instanceof org.gradle.plugins.ide.eclipse.model.ProjectDependency }
  47. .each {
  48. it.entryAttributes['without_test_code'] = 'false'
  49. it.entryAttributes['test'] = 'false'
  50. }
  51. }
  52. }
  53. }
  54. jdt {
  55. file {
  56. withProperties { properties ->
  57. // there are cycles and then dependencies between projects main sources and
  58. // test sources. Relax those from error to warning
  59. properties['org.eclipse.jdt.core.circularClasspath'] = 'warning'
  60. properties['org.eclipse.jdt.core.incompleteClasspath'] = 'warning'
  61. properties['org.eclipse.jdt.core.compiler.codegen.methodParameters'] = 'generate'
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }