Skip to content

Commit c053f6f

Browse files
jvalkealjzheaux
authored andcommitted
Make eclipse/vscode project import work
- Gradle projects contain cycles which comes from dependencies to test sources which is not a problem in gradle but eclipse metadata generation is getting confused. Thus we need settings to relax errors org.eclipse.jdt.core.circularClasspath=warning org.eclipse.jdt.core.incompleteClasspath=warning - Additionally .classpath entries needs to be changes having without_test_code=false test=false - Aspects end up getting source dirs `build/classes/java/main` and `build/resources/main` which never have sources. Vscode complains about that, eclipse is fine. Remove those from entries. - In tests `htmlunit` depends on `xml-apis`. `xml-apis` are now part of jdk and eclipse complains about that. Excluse these in a gradle build. - Both eclipse and vscode don't currently work with buildship, due to project cycles and buildship cannot be configured. It's possible to create metadata from `eclipse` task manually which then can be imported. For this we need to disable automatic import in vscode using buildship. This goes to `.vscode/settings.json` workspace config. - Then with these changes user can do something like git clean -fxd && ./gradlew clean build cleanEclipse eclipse -x checkstyleNohttp -x test -x integrationTest and import projects manually.
1 parent d8db849 commit c053f6f

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.import.gradle.enabled": false
3+
}

buildSrc/src/main/groovy/io/spring/gradle/convention/AbstractSpringJavaPlugin.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public abstract class AbstractSpringJavaPlugin implements Plugin<Project> {
5454
pluginManager.apply("io.spring.convention.javadoc-options");
5555
pluginManager.apply("io.spring.convention.checkstyle");
5656
pluginManager.apply(CopyPropertiesPlugin);
57+
pluginManager.apply("io.spring.convention.eclipse");
5758

5859
project.jar {
5960
manifest.attributes["Created-By"] =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
implementation-class=io.spring.gradle.convention.EclipsePlugin

config/spring-security-config.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ dependencies {
6868
testImplementation 'ldapsdk:ldapsdk:4.1'
6969
testImplementation('net.sourceforge.htmlunit:htmlunit') {
7070
exclude group: 'commons-logging', module: 'commons-logging'
71+
exclude group: 'xml-apis', module: 'xml-apis'
7172
}
7273
testImplementation "org.apache.directory.server:apacheds-core"
7374
testImplementation "org.apache.directory.server:apacheds-core-entry"
@@ -83,6 +84,7 @@ dependencies {
8384
testImplementation "org.mockito:mockito-inline"
8485
testImplementation('org.seleniumhq.selenium:htmlunit-driver') {
8586
exclude group: 'commons-logging', module: 'commons-logging'
87+
exclude group: 'xml-apis', module: 'xml-apis'
8688
}
8789
testImplementation('org.seleniumhq.selenium:selenium-java') {
8890
exclude group: 'commons-logging', module: 'commons-logging'

0 commit comments

Comments
 (0)