eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

apt feature request

Open ebtone opened this issue 1 year ago • 4 comments

Hi:

      The APT annotation processor can be configuration output directory? Developer can specify file location.

      Please help me! Thanks!

e.g.

settings.json

{       "org.eclipse.jdt.apt.genSrcDir": "/path/to/directory",       "org.eclipse.jdt.apt.genTestSrcDir": "/path/to/directory" }

            On java method: org.eclipse.jdt.ls.core.internal.managers.GradleBuildSupport#syncAnnotationProcessingConfiguration

                  AptConfig.setGenSrcDir(javaProject, GENERATED_SOURCES_PATH);                   AptConfig.setGenTestSrcDir(javaProject, GENERATED_TEST_SOURCES_PATH);

      change to

                  AptConfig.setGenSrcDir(javaProject, preferencesManager.getPreferences().getGeneratedSourcesPath());                   AptConfig.setGenTestSrcDir(javaProject, preferencesManager.getPreferences().getGeneratedTestSourcesPath());

ebtone avatar Sep 03 '23 10:09 ebtone

BTW, is this request comes because of the current code generation location is not the same as the build tool's?

jdneo avatar Sep 07 '23 04:09 jdneo

BTW, is this request comes because of the current code generation location is not the same as the build tool's?

Yes, I am using vscode “Extension Pack for Java (It's depends eclipse.jdt.ls)” develp Java Project, Project build tool is Gralde, and integerate Gralde plugin eclipse,Gradle annotation processor output dir is “/build/generated/sources/annotationProcessor/java/main”,and can change location,but eclipse.jdt.ls annotation processor output dir is fixed, and can not change location, finally project generation twos annotation source code, on build workspace or build project throw warnning or error.

ebtone avatar Sep 09 '23 05:09 ebtone

Thre is a workaround for the problem. We are recently exploring a new way to support Gradle project. Below are the steps:

  • install the latest pre-release of Gradle for Java extension Picture1
  • Run Java: Clean Java Language Server Workspace > Reload and Delete
  • After reload, if you still see image in the Java Projects explorer, it indicates that the project is still imported by Buildship, you need to clean and reload again. (This is caused by some issues that the bundle is not registered for the first time in a new workspace)
  • You should see logs image in those two output channel if the new importer is working.

In short, the new approach will delegate the build job to Gradle. The java extension is not responsible to generate .class files anymore. Gradle build tool will be used to do the compilation.

So, there will only be one folder to put the generated code. If you would like to try it and find any problem, please let me know.

jdneo avatar Sep 10 '23 07:09 jdneo

Thanks, But I don't want to integrate Gradle Plugin, I use the Gradle command-line interface to compile the source code, Fast and Lightweight.

for example, .\gradlew.bat clean build, the got two ouput

BTW, The java extension will delegate the build job to Gradle Plugin, User is not yet known.

/* Integrate of Eclipse */
eclipse {
    project {
        natures "org.eclipse.jdt.core.javanature"
        natures "org.eclipse.buildship.core.gradleprojectnature"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "org.eclipse.buildship.core.gradleprojectbuilder"
    }

    classpath {
        containers "org.eclipse.buildship.core.gradleclasspathcontainer"
        defaultOutputDir sourceSets.main.output.classesDirs.singleFile
        file {
            whenMerged { classpath ->
                def paths = classpath.entries.findAll { entry -> entry instanceof org.gradle.plugins.ide.eclipse.model.SourceFolder } .collect { entry ->
                    if (entry.path.startsWith("src/test/")) {
                        entry.output = project.relativePath(entry.path.startsWith("src/test/resources") ? sourceSets.test.output.resourcesDir : sourceSets.test.output.classesDirs.singleFile)
                    } else {
                        entry.output = project.relativePath(entry.path.startsWith("src/main/resources") ? sourceSets.main.output.resourcesDir : sourceSets.main.output.classesDirs.singleFile)
                    }
                    entry.path
                }
                sourceSets.main.output.generatedSourcesDirs.each { generatedSourcesDir ->
                    def path = project.relativePath(generatedSourcesDir).replaceAll("\\\\", "/");
                    if (!paths.contains(path)) {
                        classpath.entries << new org.gradle.plugins.ide.eclipse.model.SourceFolder(path, project.relativePath(sourceSets.main.output.classesDirs.singleFile))
                    }
                }
            }
        }
    }
}

image

ebtone avatar Sep 12 '23 07:09 ebtone