eclipse-jdtls / eclipse.jdt.ls

Java language server
1.8k stars 400 forks source link

apt feature request #2832

Open ebtone opened 1 year ago

ebtone commented 1 year ago

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());

jdneo commented 1 year ago

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

ebtone commented 1 year ago

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.

jdneo commented 1 year ago

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

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.

ebtone commented 1 year ago

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