我尝试将 Gradle 与 Play 框架结合使用。
在命令行中一切正常,我能够运行 Gradle 存储库中定义的简单 Play 项目示例。
但是,我在使用 Eclipse IDE(以及 Gradle Eclipse 插件)时遇到了一些问题。
似乎 app/* 文件夹中的源代码没有添加到类路径中,并且 Eclipse 项目依赖项没有显示任何内容。
我在这里看到过类似的 IntelliJ IDE 帖子:How to make gradle / intellij / play framework work together?但我正在努力在 Eclipse 上找到解决方案。
我尝试首先定义源集,例如:
sourceSets {
main {
java {
srcDirs = ['app']
}
}
}
然后我得到:
Could not find method sourceSets() for arguments [build_3exdvo6dxtqw4f3blywgxzcg3$_run_closure5@50cee09a] on root project 'play-2.4'.
所以我添加
apply plugin: 'java'
与 Gradle Play 插件一起使用时似乎失败:
Failed to apply plugin [class 'org.gradle.api.plugins.BasePlugin'] Cannot add a configuration with name 'default' as a configuration with that name already exists.
Gradle 2.10/Eclipse 4.5.1/Play 2.4
任何帮助表示赞赏。谢谢。
最佳答案
我终于找到了一种让这一切协同工作的方法。
阅读有关 Eclipse 插件 ( https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.eclipse.model.EclipseClasspath.html ) 的 Gradle 文档,可以通过提供额外的配置来覆盖 Eclipse 类路径。
因此,通过在我的 build.gradle 中使用以下行,Play 依赖项已成功解决:
eclipse.classpath.plusConfigurations += [ configurations.play ]
此外,文档指定可以通过以下方式添加类路径文件夹:
eclipse.classpath.file {
withXml {
def node = it.asNode()
node.appendNode('classpathentry kind="src" path="app"')
}
}
不幸的是,它似乎不适用于声明为 Play 插件的项目(我不明白为什么)。
我的解决方法是应用java-base 插件并指定正确的源集。
这是最终的 build.gradle:
apply plugin: 'java-base'
apply plugin: 'play'
apply plugin: 'eclipse'
version = '1.0'
model {
components {
play {
platform play: '2.4.6', scala: '2.11'
injectedRoutesGenerator = true
}
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven {
name "typesafe-maven-release"
url "https://repo.typesafe.com/typesafe/maven-releases"
}
ivy {
name "typesafe-ivy-release"
url "https://repo.typesafe.com/typesafe/ivy-releases"
layout "ivy"
}
}
}
dependencies {
play project(":common")
play 'com.typesafe.play:filters-helpers_2.11:2.4.6'
}
eclipse.classpath.plusConfigurations += [ configurations.play ]
sourceSets {
main {
java {
srcDir 'app'
}
}
}
希望对你有帮助。
关于java - 如何让gradle/Eclipse/play框架协同工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35206847/