scala 如何使用 Maven 依赖项将 Play Framework 2.0 集成到 Gradle 构建管理中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10299815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 04:07:00  来源:igfitidea点击:

How to integrate Play Framework 2.0 into Gradle build management using Maven dependencies?

scalamavenplayframeworkgradleplayframework-2.0

提问by Kai W?hner

Play framework 2.0 is a full-stack standalone framework for creating web applications. Probably, many people need to integrate it into their build management, nevertheless. Unfortunately, I did not find much information about his.

Play 框架 2.0 是一个用于创建 Web 应用程序的全栈独立框架。尽管如此,许多人可能需要将其集成到他们的构建管理中。不幸的是,我没有找到太多关于他的信息。

Here is my use case: I want to create a new project, which uses Scala and Play 2.0. I do NOT want to use sbt. I want to use Gradle, and dependency management should be done via Maven repositories.

这是我的用例:我想创建一个使用 Scala 和 Play 2.0 的新项目。我不想使用 sbt。我想使用 Gradle,依赖管理应该通过 Maven 存储库完成。

I have only found this play module: http://www.playframework.org/modules/maven-1.0/homewhich supports dependency management via Maven.

我只找到了这个播放模块:http: //www.playframework.org/modules/maven-1.0/home,它支持通过 Maven 进行依赖管理。

I am looking for something like these examples in Grails: https://github.com/grails/grails-gradle-pluginor http://grails.org/doc/latest/guide/commandLine.html#4.5%20Ant%20and%20Maven

我正在 Grails 中寻找类似这些示例的内容:https: //github.com/grails/grails-gradle-pluginhttp://grails.org/doc/latest/guide/commandLine.html#4.5%20Ant%20and %20Maven

Of course, I could write scripts / tasks which call "play console commands". Though, I do not like this solution. Is there a better way to use Gradle / Maven for build management? If this is the only solution, then I would use Gradle, which then calls Play commands (i.e. sbt internally), right? Does this even work, or will there emerge other problems?

当然,我可以编写调用“播放控制台命令”的脚本/任务。虽然,我不喜欢这个解决方案。有没有更好的方法来使用 Gradle/Maven 进行构建管理?如果这是唯一的解决方案,那么我会使用 Gradle,然后调用 Play 命令(即内部 sbt),对吗?这是否有效,还是会出现其他问题?

采纳答案by rodion

This is a very tricky business. SBT in Play is used for fetching dependencies, compiling source and templates, and for the SBT incremental compilation + auto-reloading feature. I have written a build.gradlescript to resolve all Play 2.0 dependencies and set-up Eclipse or IntelliJ IDEA classpaths, and made it public here.

这是一项非常棘手的业务。SBT in Play 用于获取依赖项、编译源代码和模板,以及用于 SBT 增量编译 + 自动重新加载功能。我编写了一个build.gradle脚本来解决所有 Play 2.0 依赖项并设置 Eclipse 或 IntelliJ IDEA 类路径,并在此处公开

I will try to implement the compilation later when I have time, but that would require some research. Of course, you can add compile and run tasks that just delegate to SBT but that would require describing all your project dependencies in both SBT and Gradle, which will become difficult to manage.

稍后我有时间时会尝试实现编译,但这需要一些研究。当然,您可以添加仅委托给 SBT 的编译和运行任务,但这需要在 SBT 和 Gradle 中描述您的所有项目依赖项,这将变得难以管理。

Edit:

编辑:

I have updated the sample build.gradlefile. I have added playCompileand playCleantasks that should help in a CI environment. The playCompiletask does the following:

我已经更新了示例 build.gradle文件。我已经加入playCompile,并playClean应在CI环境帮助任务。该playCompile任务执行以下操作:

  1. Copy all user dependencies (defined in compileconfiguration) to lib/folder. This works because Play will kindly pick up all jars from under lib/.
  2. Execute play compilecommand to compile all sources, templates and other Play framework stuff.
  1. 将所有用户依赖项(在compile配置中定义)复制到lib/文件夹。这是有效的,因为 Play 会善意地从下拿起所有罐子lib/
  2. 执行play compile命令来编译所有源代码、模板和其他 Play 框架的东西。

You can use cleanCopyPlayLibsand playCleanto remove the output of the above commands, respectively.

您可以分别使用cleanCopyPlayLibsplayClean删除上述命令的输出。

Note that there appears to be a strange problem (bug?) on Windows, which means that even if play compilefails, gradle will tell you it succeeded.

请注意,Windows 上似乎存在一个奇怪的问题(bug?),这意味着即使play compile失败,gradle 也会告诉您它成功了。

Reply to comment:

回复评论:

I think you are simply missing

我想你只是想念

repositories{
  mavenCentral()
}

in your file. Check this doc out.

在您的文件中。查看此文档

回答by mana

Good news, as of Gradle 2.7 there is an official play plugin: https://docs.gradle.org/current/userguide/play_plugin.html

好消息,从 Gradle 2.7 开始,有一个官方播放插件:https: //docs.gradle.org/current/userguide/play_plugin.html

回答by spierce7

LinkedIn is currently making a Gradle plugin to support this. They are rolling this out in 3 milestones:

LinkedIn 目前正在制作一个 Gradle 插件来支持这一点。他们将在 3 个里程碑中推出此功能:

  1. Using Gradle to build a Play application
  2. Continuous Mode and Hot-Reload
  3. Scala interactive REPL
  1. 使用 Gradle 构建 Play 应用程序
  2. 连续模式和热重载
  3. Scala 交互式 REPL

Milestone 1 is already complete.It's available via the Gradle nightly builds. On the above linked blog post, they encourage people to give it a try.

里程碑 1 已经完成。它可以通过Gradle nightly builds 获得。在上面链接的博客文章中,他们鼓励人们尝试一下。

回答by Kiran

I designed a simple build script in Gradle for Play Framework 1.2.x which you could also use for Play 2.x

我在 Gradle 中为 Play Framework 1.2.x 设计了一个简单的构建脚本,您也可以将其用于 Play 2.x

https://github.com/kirang89/play-gradle

https://github.com/kirang89/play-gradle