according this issue about automatically configuring classpath and build settings for an Eclipse project that uses the Gradle build tool. Configuring classpath and build settings in Eclipse for a Gradle project involves a few steps. Here is a framework for auto-configuring the classpath using the Eclipse Gradle plugin:

Install Eclipse Gradle Plugin

activate eclipse plugin each gradle subprojects

Using plugins block

plugins {
  id "eclipse"
}

Using native classpath

apply plugin: 'eclipse'

Configure eclipse .classpath generation

Configure eclipse .classpath generation using eclipse block

Groovy

eclipse {
  classpath {
    defaultOutputDir = file('build/eclipse')
    file.whenMerged {
      entries.each { entry ->
        if (entry.kind == 'src' && entry.hasProperty('output')) {
          entry.output = entry.output.replace('bin/', "build/eclipse/")
        }
      }
    }
  }
}

Kotlin DSL

import org.gradle.plugins.ide.eclipse.model.Classpath
import org.gradle.plugins.ide.eclipse.model.SourceFolder
plugins {
    java
    eclipse
}
buildDir = file("build/gradle")
eclipse {
    classpath {
        defaultOutputDir = file("build/eclipse")
        file {
            whenMerged(
                    Action<Classpath> { ->
                        entries.filter { it.kind == "src" }.forEach {
                            if (it is SourceFolder) {
                                it.output = it.output.replace("bin/", "build/eclipse/")
                            }
                        }
                    }
            )
        }
    }
}

Sync with gradle build output classes and resources

You also can sync between eclipse output and gradle output classes and resources with below gradle config:

eclipse {
    classpath {
        defaultOutputDir = file('build')
        baseSourceOutputDir = file('build/classes/java')
        file.whenMerged {
            entries.each { entry ->
                if (entry.kind == 'src' && entry.hasProperty('output')) {
                    if (entry.path == "src/main/java") {
                        entry.output = "build/classes/java/main"
                    } else if (entry.path == "src/main/resources") {
                        entry.output = "build/resources/main"
                    } else if (entry.path == "src/test/resources") {
                        entry.output = "build/resources/test"
                    } else if (entry.path == "src/test/java") {
                        entry.output = "build/classes/java/test"
                    } else if (entry.path == "src/test/groovy") {
                        entry.output = "build/classes/groovy/test"
                    } else if (entry.path == "src/main/groovy") {
                        entry.output = "build/classes/groovy/main"
                    } else if (entry.path == "src/main/kotlin") {
                        entry.output = "build/classes/kotlin/main"
                    } else if (entry.path == "src/test/kotlin") {
                        entry.output = "build/classes/kotlin/test"
                    } else  {
                        println(entry.path)
                    }
                    if (entry.output != null) entry.output = entry.output.replace('bin/', "build/")
                }
            }
        }
    }
}

Generate Eclipse Files

  • Open a terminal and navigate to your project directory.
  • Run the following Gradle command to generate Eclipse files:
gradlew eclipse

This task generates the necessary .project and .classpath files for your Eclipse project.

Conclusion

By following these steps, you should have successfully configured your Eclipse project with the Gradle build tool. Keep in mind that these instructions may vary slightly depending on your specific project structure and requirements.