Synchronize gradle projects with workspace failed due to an unexpected error

issue-resolved
buildship
eclipse

(PP) #1

Hello, i have gradle 4.5.1, buildship 2.2, java 7 and tomcat 7.0.47. I could build project with buildship 2.2 and gradle 4.2 successfully. and make my local server up with tomcat 7.0.47.

But after upgrading to gradle 4.5.1. I can not make my local server up using tomcat, The error i was getting was:

`eclipse.buildId=4.6.3.M20170301-0400

java.version=1.8.0_121
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product org.eclipse.epp.package.java.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product

org.eclipse.jdt.core
Error
Fri Mar 16 11:45:07 IST 2018
Cannot nest output folder ‘sample/bin/main’ inside output folder ‘sample/bin’`

To remove this error i removed out kind entry from .classpath file of eclipse and i could run it successfully.
Now to remove this i have added patch as:

if (classpathEntry.kind == 'output') {
                    if (classpathEntry.path == 'bin/default') {
                        entriesToBeRemoved << classpathEntry
                    }
                }

But now when refreshing project with buildship 2.2. I am getting below exception:

synchronize gradle projects with workspace failed due to an unexpected error
Cannot nest output folder 'sample/bin/main' inside output folder 'sample/bin'
Java Model Exception: Java Model Status [Cannot nest output folder 'sample/bin/main' inside output folder 'sample/bin'] at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:786) at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3102) at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3064) at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3076) at org.eclipse.jdt.internal.core.JavaProject.setOutputLocation(JavaProject.java:3023) at org.eclipse.buildship.core.workspace.internal.OutputLocationUpdater.update(OutputLocationUpdater.java:31) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeJavaProjectInTransaction(SynchronizeGradleBuildOperation.java:244) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.access$200(SynchronizeGradleBuildOperation.java:99) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation$4.run(SynchronizeGradleBuildOperation.java:234) at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39) at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:724) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267) at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5521) at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5478) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeJavaProject(SynchronizeGradleBuildOperation.java:230) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeOpenWorkspaceProject(SynchronizeGradleBuildOperation.java:221) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeWorkspaceProject(SynchronizeGradleBuildOperation.java:186) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeGradleProjectWithWorkspaceProject(SynchronizeGradleBuildOperation.java:176) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.access$000(SynchronizeGradleBuildOperation.java:99) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation$1.run(SynchronizeGradleBuildOperation.java:134) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2262) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeProjectsWithWorkspace(SynchronizeGradleBuildOperation.java:131) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.run(SynchronizeGradleBuildOperation.java:115) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildsJob.synchronizeBuild(SynchronizeGradleBuildsJob.java:85) at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildsJob.runToolingApiJob(SynchronizeGradleBuildsJob.java:73) at org.eclipse.buildship.core.util.progress.ToolingApiJob$1.run(ToolingApiJob.java:73) at org.eclipse.buildship.core.util.progress.ToolingApiInvoker.invoke(ToolingApiInvoker.java:62) at org.eclipse.buildship.core.util.progress.ToolingApiJob.run(ToolingApiJob.java:70) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Can you please help?


(Donát Csikós) #2

You should not remove the output folder from the list of classpath entries because then the default <project_name>/bin will be picked up. Can you try setting a custom value for the eclipse.classpath.defaultOutputDir property?


(PP) #3

Thanks Donat. I resolved my problem


(PP) #4

Hi Donat,
New problem arose here. I am using rootProject.projectDir in my build.gradle which is giving me path till bin folder and i have changed default output folder to bin/main. Which is failing all existing code.

Can you suggest does gradle handle eclipse differently?


(Donát Csikós) #5

bin/main is the output folder for the main source set. How about using the default bin/default path?


(PP) #6

bin/default is not allowing tomcat plugin to start. tomcat plugin do not instantiate even.
it is giving error as
’eclipse.buildId=4.6.3.M20170301-0400
java.version=1.8.0_121
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product org.eclipse.epp.package.java.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product

org.eclipse.jdt.core
Error
Fri Mar 16 11:45:07 IST 2018
Cannot nest output folder ‘sample/bin/main’ inside output folder ‘sample/bin’ ’


(Donát Csikós) #7

Ah, correct, I forgot that we started here. Still, I think you should be able to make your project work by:

  • setting the default output dir to bin
  • setting a separate output for each source folder: sourceSetBin/main and sourceSetBin/test.
    Or, you can try removing the output location from the source folders altogether, but it breaks the runtime classpath separation functionality (when you run a main() method or when you run a JUnit test from Eclipse).

(PP) #8

setting the default output dir to bin:
That i have done.
setting a separate output for each source folder:
Can you please tell how can i do this?


(Donát Csikós) #9

You can do something like this:

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    classpath {
        file {
            whenMerged {
                def src = entries.find { it.path == 'src/main/java' }
                src.output = "/$eclipse.project.name/sourceSetBin/main"
            }
        }
    }
}

(PP) #10

getting same error
Java Model Exception: Java Model Status [Cannot nest output folder 'sample/bin/main' inside output folder 'sample/bin']


(Sølve) #11

An old issue, but try deleting all the eclipse related/directories within your project, e.g., .project, .classpath and .settings then re-import the project and it should work; had the same issue.