【发布时间】:2015-12-18 15:39:31
【问题描述】:
我当前的配置包括一个使用带有 java 和 eclipse-wtp 插件的 gradle 的 Java WAR 项目,以及最新版本的 Buildship for Eclipse 集成(今天早上是 1.0.3,现在是 1.0.4)以及 Eclipse Luna。
在遵循此解决方案https://stackoverflow.com/a/9820317/1544713(成功)以避免将测试类部署到我的本地服务器后,我注意到每次刷新项目或关闭并打开 Eclipse 时,.classpath 文件和.settings/org.eclipse.wst.common.component 都已更改到他们以前的状态,这给我带来了问题(将测试类部署到本地服务器意味着由于缺乏一些测试时间依赖性,当然还有不希望的行为,它们将无法加载)。
.classpath的内容由(右)改变:
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
到这种不希望的状态:
<classpathentry kind="src" path="src/test/java">
<attributes>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/test/resources">
<attributes>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
</classpathentry>
对于.settings/org.eclipse.wst.common.component,添加了这两行(同样,我不希望它们出现):
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
我不知道是 Gradle 正在更改文件还是 Buildship,甚至是 Eclipse。无论如何,我想有办法阻止这种情况发生。我尝试了很多替代方案,例如 build.gradle 中的以下配置:
eclipse.classpath.file.whenMerged { cp ->
cp.entries.findAll { it.kind = "src" && it.path.startsWith("src/test/") }*.output = "target/test-classes"
}
eclipse {
wtp.component {
file.withXml { xml ->
def node = xml.asNode()
def wbrNodes = node.'**'.findAll { it.name() == 'wb-resource' && it.'@source-path'.startsWith("/src/test/")}
if (wbrNodes.size() > 0) {
wbrNodes.each { n -> n.parent().remove(n) }
}
}
}
}
但是这种配置工作不规律(有时它似乎工作,有时它不工作,实际上以 eclipse.classpath.file.whenMerged 开头的第一段代码永远不会工作)。
提前致谢。
【问题讨论】:
-
到目前为止,我还没有找到任何东西。似乎 Buildship 正在重写
.classpath和.settings/*文件以方便自己,我无法为 src/test 设置不同的输出目录。
标签: java eclipse gradle eclipse-wtp