ide.gradle 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import org.gradle.plugins.ide.eclipse.model.ProjectDependency
  2. import org.gradle.plugins.ide.eclipse.model.SourceFolder
  3. apply plugin: "eclipse"
  4. eclipse.jdt {
  5. sourceCompatibility = 1.8
  6. targetCompatibility = 1.8
  7. }
  8. // Replace classpath entries with project dependencies (GRADLE-1116)
  9. // https://issues.gradle.org/browse/GRADLE-1116
  10. eclipse.classpath.file.whenMerged { classpath ->
  11. def regexp = /.*?\/([^\/]+)\/build\/([^\/]+\/)+(?:main|test)/ // only match those that end in main or test (avoids removing necessary entries like build/classes/jaxb)
  12. def projectOutputDependencies = classpath.entries.findAll { entry -> entry.path =~ regexp }
  13. projectOutputDependencies.each { entry ->
  14. def matcher = (entry.path =~ regexp)
  15. if (matcher) {
  16. def projectName = matcher[0][1]
  17. def path = "/${projectName}"
  18. if(!classpath.entries.find { e -> e instanceof ProjectDependency && e.path == path }) {
  19. def dependency = new ProjectDependency(path)
  20. dependency.exported = true
  21. classpath.entries.add(dependency)
  22. }
  23. classpath.entries.remove(entry)
  24. }
  25. }
  26. classpath.entries.removeAll { entry -> (entry.path =~ /(?!.*?repack.*\.jar).*?\/([^\/]+)\/build\/libs\/[^\/]+\.jar/) }
  27. }
  28. // Use separate main/test outputs (prevents WTP from packaging test classes)
  29. eclipse.classpath.defaultOutputDir = file(project.name+"/bin/eclipse")
  30. eclipse.classpath.file.beforeMerged { classpath ->
  31. classpath.entries.findAll{ it instanceof SourceFolder }.each {
  32. if (it.output.startsWith("bin/")) {
  33. it.output = null
  34. }
  35. }
  36. }
  37. eclipse.classpath.file.whenMerged { classpath ->
  38. classpath.entries.findAll{ it instanceof SourceFolder }.each {
  39. it.output = "bin/" + it.path.split("/")[1]
  40. }
  41. }
  42. // Ensure project dependencies come after 3rd-party libs (SPR-11836)
  43. // https://jira.spring.io/browse/SPR-11836
  44. eclipse.classpath.file.whenMerged { classpath ->
  45. classpath.entries.findAll { it instanceof ProjectDependency }.each {
  46. // delete from original position
  47. classpath.entries.remove(it)
  48. // append to end of classpath
  49. classpath.entries.add(it)
  50. }
  51. }
  52. // Allow projects to be used as WTP modules
  53. eclipse.project.natures "org.eclipse.wst.common.project.facet.core.nature"
  54. // Include project specific settings
  55. task eclipseSettings(type: Copy) {
  56. from rootProject.files(
  57. "src/eclipse/org.eclipse.jdt.ui.prefs",
  58. "src/eclipse/org.eclipse.wst.common.project.facet.core.xml")
  59. into project.file('.settings/')
  60. outputs.upToDateWhen { false }
  61. }
  62. task eclipseWstComponent(type: Copy) {
  63. from rootProject.files(
  64. "src/eclipse/org.eclipse.wst.common.component")
  65. into project.file('.settings/')
  66. expand(deployname: project.name)
  67. outputs.upToDateWhen { false }
  68. }
  69. task eclipseJdtPrepare(type: Copy) {
  70. from rootProject.file("src/eclipse/org.eclipse.jdt.core.prefs")
  71. into project.file(".settings/")
  72. outputs.upToDateWhen { false }
  73. }
  74. task cleanEclipseJdtUi(type: Delete) {
  75. delete project.file(".settings/org.eclipse.jdt.core.prefs")
  76. delete project.file(".settings/org.eclipse.jdt.ui.prefs")
  77. delete project.file(".settings/org.eclipse.wst.common.component")
  78. delete project.file(".settings/org.eclipse.wst.common.project.facet.core.xml")
  79. }
  80. task eclipseBuildship(type: Copy) {
  81. from rootProject.files(
  82. "src/eclipse/org.eclipse.jdt.ui.prefs",
  83. "src/eclipse/org.eclipse.jdt.core.prefs")
  84. into project.file('.settings/')
  85. outputs.upToDateWhen { false }
  86. }
  87. tasks["eclipseJdt"].dependsOn(eclipseJdtPrepare)
  88. tasks["cleanEclipse"].dependsOn(cleanEclipseJdtUi)
  89. tasks["eclipse"].dependsOn(eclipseSettings, eclipseWstComponent)
  90. // Filter 'build' folder
  91. eclipse.project.file.withXml {
  92. def node = it.asNode()
  93. def filteredResources = node.get("filteredResources")
  94. if(filteredResources) {
  95. node.remove(filteredResources)
  96. }
  97. def filterNode = node.appendNode("filteredResources").appendNode("filter")
  98. filterNode.appendNode("id", "1359048889071")
  99. filterNode.appendNode("name", "")
  100. filterNode.appendNode("type", "30")
  101. def matcherNode = filterNode.appendNode("matcher")
  102. matcherNode.appendNode("id", "org.eclipse.ui.ide.multiFilter")
  103. matcherNode.appendNode("arguments", "1.0-projectRelativePath-matches-false-false-build")
  104. }