diff --git a/org.eclipse.jdt.ls.core/gradle/init/init.gradle b/org.eclipse.jdt.ls.core/gradle/init/init.gradle index ba83af2db5..5749fcce06 100644 --- a/org.eclipse.jdt.ls.core/gradle/init/init.gradle +++ b/org.eclipse.jdt.ls.core/gradle/init/init.gradle @@ -3,6 +3,8 @@ allprojects { // Add prefix when project name has conflicts with root project name if (project != rootProject && rootProject.name.toLowerCase() == project.name.toLowerCase()) { eclipse.project.name = (rootProject.name + project.path).replaceAll(':', '-') + } else if (project == rootProject && rootProject.name.toLowerCase() != project.projectDir.name.toLowerCase()) { + eclipse.project.name = (rootProject.name + '-' + project.projectDir.name).replaceAll(':', '-') } }) } diff --git a/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/complete/build.gradle b/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/complete/build.gradle new file mode 100644 index 0000000000..f12c222de9 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/complete/build.gradle @@ -0,0 +1,15 @@ +plugins { + id 'java' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '17' + +repositories { + mavenCentral() +} + +dependencies { + +} diff --git a/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/complete/settings.gradle b/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/complete/settings.gradle new file mode 100644 index 0000000000..b75ef0f2d2 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/complete/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'rest-service' diff --git a/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/initial/build.gradle b/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/initial/build.gradle new file mode 100644 index 0000000000..bf2ae703c9 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/initial/build.gradle @@ -0,0 +1,16 @@ +plugins { + id 'java' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '17' + +repositories { + mavenCentral() +} + +dependencies { + +} + diff --git a/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/initial/settings.gradle b/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/initial/settings.gradle new file mode 100644 index 0000000000..b75ef0f2d2 --- /dev/null +++ b/org.eclipse.jdt.ls.tests/projects/gradle/nameconflict2/initial/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'rest-service' diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporterTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporterTest.java index d96ced73ca..cc83328c03 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporterTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporterTest.java @@ -636,6 +636,17 @@ public void testNameConflictProject() throws Exception { assertIsGradleProject(subProject); } + // https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/1743 + @Test + public void testNameConflictProject2() throws Exception { + List projects = importProjects("gradle/nameconflict2"); + assertEquals(2, projects.size()); + IProject project1 = WorkspaceHelper.getProject("rest-service-initial"); + assertIsGradleProject(project1); + IProject project2 = WorkspaceHelper.getProject("rest-service-complete"); + assertIsGradleProject(project2); + } + @Test public void testAndroidProjectSupport() throws Exception { try {