我正在使用Gradle和Eclipse与Buildship插件。
Buildship为Eclipse创建要使用的.classpath文件。由于类加载的原因,我需要一个类路径条目(com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER)出现在org.eclipse.buildship.core.gradleclasspathcontainer条目之后。
因此,我的.classpath文件的相关部分应该如下所示( GWT_CONTAINER位于底部)。
<classpath>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer" />
<classpathentry kind="con" path="com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER"/>
</classpath>Buildship总是在最后一个位置有gradleclasspathcontainer。因此,我试图在我的build.gradle (摘录)中这样更改排序:
eclipse {
classpath {
file {
beforeMerged { classpath ->
def gwtClasspath = classpath.entries.find { entry -> entry.path == 'com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER' }
classpath.entries.remove gwtClasspath
classpath.entries << gwtClasspath
}
}
}使用./gradlew eclipseClasspath时,将正确创建.classpath文件。但是,一旦Buildship运行,文件就会再次被错误的顺序覆盖。
我也尝试使用whenMerged而不是beforeMerged,但这并没有改变任何事情。
下面是由Buildship启动的Gradle输出(例如,单击Eclipse属性上的Gradle ->刷新):
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5/userguide/command_line_interface.html#sec:command_line_warnings
CONFIGURE SUCCESSFUL in 0s
:cleanEclipseWtpComponent
:cleanEclipseWtpFacet
:cleanEclipseWtp
:eclipseWtpComponent
:eclipseWtpFacet
:eclipseWtp
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 0s
4 actionable tasks: 4 executed看起来Buildship甚至没有执行eclipseClasspath任务,但是确实通过其他方式创建了.classpath文件。
我怎样才能得到建设,以履行我的愿望,使类路径排序我的方式?
发布于 2018-03-19 17:55:54
我找到了分级论坛的解决方案
Buildship不使用eclipseClasspath任务,而是通过自己的方式读取配置并创建.classpath。如果尚未定义Gradle类路径,则将其追加到类路径的末尾。这是在执行whenMerged部分之后发生的。因此,解决方案是手动添加Gradle类路径:
eclipse {
classpath {
containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
}
}发布于 2018-03-02 13:26:30
也许withXml钩子的工作方式会有所不同
eclipse.classpath.file {
withXml { provider ->
def entry = provider.asNode().classpath.classpathentry.find { it.path == 'com.gwtplugins.gwt.eclipse.core.GWT_CONTAINER' }
println "Found $entry"
def parent = entry.parent()
parent.remove(entry)
parent.append(entry)
}
}https://stackoverflow.com/questions/49068870
复制相似问题