我试图在Eclipse中使用gradle项目,但出现以下错误
Synchronize Gradle projects with workspace failed due to an unexpected error.
Cannot nest 'iC/src/java' inside 'iC'. To enable the nesting exclude 'src/' from 'iC'
Java Model Exception: Java Model Status [Cannot nest 'iC/src/java' inside 'iC'. To enable the nesting exclude 'src/' from 'iC']
at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:798)
at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3559)
at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3519)
at org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(JavaProject.java:3575)
at org.eclipse.buildship.core.workspace.internal.SourceFolderUpdater.updateSourceFolders(SourceFolderUpdater.java:72)
at org.eclipse.buildship.core.workspace.internal.SourceFolderUpdater.update(SourceFolderUpdater.java:174)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeJavaProjectInTransaction(SynchronizeGradleBuildOperation.java:245)
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:41)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:736)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2319)
at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5736)
at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5693)
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:2292)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2314)
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:63)
我将错误范围缩小到了这段黑色代码
sourceSets{
test {
resources {
srcDirs = [projectDir]
['.gradle','build.gradle','gradle','gradlew','gradlew.bat','bin','branding','compsciBuild','db','html','images','jsp','logs','META-INF','scripts','src','styles','theme','web','WEB-INF','build','.svn','reports'].each{excludes->
exclude excludes
}
}
}
}
我不知道必须重写该块以允许我的junit测试正常运行。如果我仅包含
,则会出现错误sourceSets.test.resources.srcDirs = ["${projectDir}/data"]
在我的junit日志中是以下内容
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autopilot' defined in URL [file:etc/applicationContext-parsing.xml]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.compsci.ic.parser.rr.Autopilot]: Constructor threw exception; nested exception is java.io.FileNotFoundException: class path resource [data/autopilotCorpus] cannot be resolved to absolute file path because it does not exist
我知道我可以重写junit测试,以更明确地说明它们在哪里寻找数据文件夹,但这不是一个选择,因为有些开发人员在进行切换之前仍在使用ant。 / p>
谢谢。
文件夹结构如下
projectDir/src/java
projectDir/test/src/java
projectDir/data
* **更新 ***
我最终按照@ M.Ricciuti的建议解决了这个问题。我最终的工作代码就是这样
sourceSets{
test {
resources {
srcDirs = [projectDir]
['.gradle/','build.gradle','gradle/','gradlew','gradlew.bat','bin/','branding/','compsciBuild/','db/','html/','images/','jsp/','logs/','META-INF/','scripts/','src/','styles/','theme/','web/','WEB-INF/','build/','.svn/','reports/', 'test/', '*.*', 'etc/', 'lib/', '.settings/'].each{excludes->
exclude excludes
}
}
}
}
答案 0 :(得分:1)
通过配置测试 SourceSets “ resources”目录,您已使用正确的方法来提供测试资源。
但是您的排除规则中有两个小错误:
test
目录