Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java eclipse的Gradle集成不断更改.classpath文件_Java_Eclipse_Gradle_Eclipse Wtp - Fatal编程技术网

Java eclipse的Gradle集成不断更改.classpath文件

Java eclipse的Gradle集成不断更改.classpath文件,java,eclipse,gradle,eclipse-wtp,Java,Eclipse,Gradle,Eclipse Wtp,我当前的配置包括一个使用gradle和Java及EclipseWTP插件的Java WAR项目,以及最新版本的用于eclipse集成的Buildship(到今天早上为止为1.0.3,现在为1.0.4)和EclipseLuna 为了避免将测试类部署到本地服务器,我(成功地)遵循此解决方案后,注意到每次刷新项目或关闭并打开Eclipse时,.classpath文件和.settings/org.Eclipse.wst.common.component都会更改为以前的状态,这是我给我带来问题的地方(将测

我当前的配置包括一个使用gradle和Java及EclipseWTP插件的Java WAR项目,以及最新版本的用于eclipse集成的Buildship(到今天早上为止为1.0.3,现在为1.0.4)和EclipseLuna

为了避免将测试类部署到本地服务器,我(成功地)遵循此解决方案后,注意到每次刷新项目或关闭并打开Eclipse时,
.classpath
文件和
.settings/org.Eclipse.wst.common.component
都会更改为以前的状态,这是我给我带来问题的地方(将测试类部署到本地服务器意味着由于缺乏一些测试时间依赖性,它们将无法加载,当然还有不希望的行为)

.classpath
的内容从(右侧)更改为:

我不知道是Gradle在更改文件或构建,甚至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,它没有注意build.gradle中对eclipse wtp插件的指令,相反,它采用自己的方法来生成
.classpath
和相关的eclipse配置文件。同时,到目前为止(Buildship 1.0.5刚刚发布),在Buildship构建自己的模型时(导入Gradle项目、打开Eclipse或刷新项目时,例如使用F5),无法配置或操作Buildship。正如Lance_Java在Gradle论坛()中所说,将eclipse wtp插件与Buildship一起使用是无用的,因为两者都采用自己的方法来生成eclipse配置文件

因此,到目前为止的解决方案是从我的Eclipse安装中删除Buildship,而代之以Eclipse marketplace中的Gradle IDE Pack 3.6.x+0.17插件,该插件使用build.Gradle指令构建自己的模型,从而避免任何可能的冲突

如果Buildship的任何人读到这篇文章,请给我们一些生成文件的钩子。同样,正如Lance_Java所建议的,类似这样的东西确实会有帮助:

apply plugin: 'buildship' 

buildship.wtp.component.file.withXml { ... }

到目前为止,我什么也没找到。Buildship似乎正在为自己的方便而重写
.classpath
.settings/*
文件,我无法为src/test设置不同的输出目录。
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
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) }
            }                   
        }
    }
}
apply plugin: 'buildship' 

buildship.wtp.component.file.withXml { ... }