Gradle eclipse 集成不断更改 .classpath 文件
Gradle integration for eclipse keeps on changing .classpath file
我当前的配置包括一个 Java WAR 项目使用 gradle 与 java 和 eclipse-wtp 插件,以及最新版本的 Buildship for Eclipse 集成( 1.0.3 到今天早上,现在是 1.0.4)以及 Eclipse Luna。
遵循此解决方案 (成功)以避免将测试 类 部署到我的本地服务器后,我注意到每次刷新项目或关闭并打开 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,它没有关注 eclipse-wtp 插件的指令在 build.gradle 中,而是采用自己的方法生成 .classpath
和相关的 eclipse 配置文件。同时,到目前为止(Buildship 1.0.5 刚刚发布)在构建自己的模型时无法配置或操作 Buildship(导入 Gradle 项目时,打开 Eclipse 时或刷新时一个项目,例如 F5)。正如 Lance_Java 在 Gradle 论坛 (https://discuss.gradle.org/t/gradle-integration-for-eclipse-keeps-on-changing-classpath-file/11813/7?u=fbudassi) 中所说,将 eclipse-wtp 插件与 Buildship 一起使用是没有用的,因为两者都采用自己的方法来生成 Eclipse 配置文件。
因此,到目前为止,解决方案是从我的 Eclipse 安装中删除 Buildship,并将其替换为 Gradle IDE Pack 3.6.x+来自 Eclipse 市场的 0.17 插件,它使用 build.gradle 指令构建自己的模型,从而避免了任何可能的冲突。
如果 Buildship 的任何人能读到这篇文章 post,请给我们一些生成文件的方法。同样,正如 Lance_Java 所建议的那样,这样的事情真的很有帮助:
apply plugin: 'buildship'
buildship.wtp.component.file.withXml { ... }
我当前的配置包括一个 Java WAR 项目使用 gradle 与 java 和 eclipse-wtp 插件,以及最新版本的 Buildship for Eclipse 集成( 1.0.3 到今天早上,现在是 1.0.4)以及 Eclipse Luna。
遵循此解决方案 (成功)以避免将测试 类 部署到我的本地服务器后,我注意到每次刷新项目或关闭并打开 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,它没有关注 eclipse-wtp 插件的指令在 build.gradle 中,而是采用自己的方法生成 .classpath
和相关的 eclipse 配置文件。同时,到目前为止(Buildship 1.0.5 刚刚发布)在构建自己的模型时无法配置或操作 Buildship(导入 Gradle 项目时,打开 Eclipse 时或刷新时一个项目,例如 F5)。正如 Lance_Java 在 Gradle 论坛 (https://discuss.gradle.org/t/gradle-integration-for-eclipse-keeps-on-changing-classpath-file/11813/7?u=fbudassi) 中所说,将 eclipse-wtp 插件与 Buildship 一起使用是没有用的,因为两者都采用自己的方法来生成 Eclipse 配置文件。
因此,到目前为止,解决方案是从我的 Eclipse 安装中删除 Buildship,并将其替换为 Gradle IDE Pack 3.6.x+来自 Eclipse 市场的 0.17 插件,它使用 build.gradle 指令构建自己的模型,从而避免了任何可能的冲突。
如果 Buildship 的任何人能读到这篇文章 post,请给我们一些生成文件的方法。同样,正如 Lance_Java 所建议的那样,这样的事情真的很有帮助:
apply plugin: 'buildship'
buildship.wtp.component.file.withXml { ... }