eclipse-jdtls / eclipse.jdt.ls

Java language server
1.81k stars 402 forks source link

Test source folder must have an output folder that is not also used for main sources #1635

Open aconchillo opened 3 years ago

aconchillo commented 3 years ago

Hi,

I'm hitting the following error when a project that has integration tests wants to use resources from main (see below):

Test source folder 'src/integration-test/java' in project 'integration-tests-issue' must have an output folder that is not also used for main sources

This works fine when calling ./gradlew integrationTest.

I'm attaching a sample project to reproduce this:

integration-tests-issue.zip

I've tracked down the issue to including "$projectDir/src/main/resources" in resources.srcDirs when defining integration tests:

resources.srcDirs = ["$projectDir/src/main/resources", "$projectDir/src/integration-test/resources"]

from

sourceSets {
    integrationTest {
        java.srcDir "$projectDir/src/integration-test/java"
    resources.srcDirs = ["$projectDir/src/main/resources", "$projectDir/src/integration-test/resources"]
        compileClasspath += main.output + test.output
        runtimeClasspath += main.output + test.output
    }
}

The fix is to simply use:

resources.srcDirs = ["$projectDir/src/integration-test/resources"]

I'm using Emacs with lsp-mode/lsp-java, but I don't think this would be related to lsp-mode/lsp-java. It might be the error is not in Eclipse JDT LS either but from the stack trace it seem it's down the line. This is the full stack trace:

Java Model Exception: Java Model Status [Test source folder 'src/integration-test/java' in project 'integration-tests-issue' must have an output folder that is not also used for main sources]
        at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:802)
        at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3608)
        at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3568)
        at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3624)
        at org.eclipse.buildship.core.internal.workspace.SourceFolderUpdater.updateSourceFolders(SourceFolderUpdater.java:71)
        at org.eclipse.buildship.core.internal.workspace.SourceFolderUpdater.update(SourceFolderUpdater.java:169)
        at org.eclipse.buildship.core.internal.workspace.BaseConfigurator.synchronizeJavaProjectInTransaction(BaseConfigurator.java:116)
        at org.eclipse.buildship.core.internal.workspace.BaseConfigurator.access$000(BaseConfigurator.java:40)
        at org.eclipse.buildship.core.internal.workspace.BaseConfigurator$1.run(BaseConfigurator.java:105)
        at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:41)
        at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:740)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
        at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5901)
        at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5858)
        at org.eclipse.buildship.core.internal.workspace.BaseConfigurator.synchronizeJavaProject(BaseConfigurator.java:101)
        at org.eclipse.buildship.core.internal.workspace.BaseConfigurator.configure(BaseConfigurator.java:91)
        at org.eclipse.buildship.core.internal.workspace.BaseConfigurator.configure(BaseConfigurator.java:66)
        at org.eclipse.buildship.core.internal.extension.InternalProjectConfigurator.configure(InternalProjectConfigurator.java:65)
        at org.eclipse.buildship.core.internal.workspace.ProjectConfigurators.configureConfigurators(ProjectConfigurators.java:70)
        at org.eclipse.buildship.core.internal.workspace.SynchronizeGradleBuildOperation.synchronizeOpenWorkspaceProject(SynchronizeGradleBuildOperation.java:163)
        at org.eclipse.buildship.core.internal.workspace.SynchronizeGradleBuildOperation.synchronizeWorkspaceProject(SynchronizeGradleBuildOperation.java:137)
        at org.eclipse.buildship.core.internal.workspace.SynchronizeGradleBuildOperation.synchronizeGradleProjectWithWorkspaceProject(SynchronizeGradleBuildOperation.java:127)
        at org.eclipse.buildship.core.internal.workspace.SynchronizeGradleBuildOperation.access$000(SynchronizeGradleBuildOperation.java:42)
        at org.eclipse.buildship.core.internal.workspace.SynchronizeGradleBuildOperation$1.run(SynchronizeGradleBuildOperation.java:85)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2312)
        at org.eclipse.buildship.core.internal.workspace.SynchronizeGradleBuildOperation.synchronizeProjectsWithWorkspace(SynchronizeGradleBuildOperation.java:82)
        at org.eclipse.buildship.core.internal.workspace.SynchronizeGradleBuildOperation.run(SynchronizeGradleBuildOperation.java:64)
        at org.eclipse.buildship.core.internal.DefaultGradleBuild$SynchronizeOperation.runInToolingApi(DefaultGradleBuild.java:230)
        at org.eclipse.buildship.core.internal.operation.DefaultToolingApiOperationManager$WorkspaceRunnableAdapter.run(DefaultToolingApiOperationManager.java:58)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
        at org.eclipse.buildship.core.internal.operation.DefaultToolingApiOperationManager.run(DefaultToolingApiOperationManager.java:39)
        at org.eclipse.buildship.core.internal.DefaultGradleBuild$SynchronizeOperation.run(DefaultGradleBuild.java:192)
        at org.eclipse.buildship.core.internal.DefaultGradleBuild.synchronize(DefaultGradleBuild.java:100)
        at org.eclipse.buildship.core.internal.workspace.SynchronizationJob.runInToolingApi(SynchronizationJob.java:64)
        at org.eclipse.buildship.core.internal.workspace.SynchronizationJob.runInToolingApi(SynchronizationJob.java:30)
        at org.eclipse.buildship.core.internal.operation.ToolingApiJob$1.runInToolingApi(ToolingApiJob.java:54)
        at org.eclipse.buildship.core.internal.operation.DefaultToolingApiOperationManager$WorkspaceRunnableAdapter.run(DefaultToolingApiOperationManager.java:58)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
        at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
        at org.eclipse.buildship.core.internal.operation.DefaultToolingApiOperationManager.run(DefaultToolingApiOperationManager.java:39)
        at org.eclipse.buildship.core.internal.operation.ToolingApiJob.run(ToolingApiJob.java:65)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
slPerryRhodan commented 3 years ago

Same issue here with: resources.srcDirs = ['src/contractTest/resources', 'src/contractTest/contracts', 'src/main/resources']

After removing 'src/main/resources' it works fine.

It doesn't produce any errors In IntelliJ. Would be nice if eclipse is also more robust in this case.

jpwilhelms commented 3 years ago

A similar problem with custom source pathes and testFixtures: https://github.com/eclipse/buildship/issues/1115

AhrazA commented 1 year ago

Are there currently any workarounds for this, aside from simply removing the srcDir? Unfortunately in my situation it isn't viable.