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