我正在尝试使用 Gradle 作为构建工具,使用 Play Framework 构建Web应用程序。我的IDE是 IntelliJ Idea 。
我将Play与和Java 一起使用,所以我不想在项目中使用 SBT 。但是 IntelliJ Idea 似乎不完全支持Play,因为项目结构完全不同。 IntelliJ无法识别它。
经过一段时间的搜索,我找到了一个解决方案,将该脚本添加到build.gradle
中:
idea {
module {
sourceDirs += file("app")
testSourceDirs += file("test")
scopes.COMPILE = [plus: [configurations.play], minus: []]
scopes.RUNTIME = [plus: [configurations.playRun], minus:[configurations.play]]
scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
}
}
但是有一个问题,每次我打开项目时,我都必须重新运行想法任务,以使IntelliJ识别Play的结构。
有什么方法比我的更好吗?
非常感谢!
我的Github示例:https://github.com/TranNgocKhoa/play-gradle-intellij-example。
我的
build.gradle
plugins {
id 'play'
id 'idea'
}
def playVersion = "2.6.7"
def scalaVersion = System.getProperty("scala.binary.version", /* default = */ "2.11")
model {
components {
play {
platform play: playVersion, scala: scalaVersion, java: '1.8'
injectedRoutesGenerator = true
sources {
twirlTemplates {
defaultImports = TwirlImports.JAVA
}
}
}
}
}
def dependencyFor(String lib, String scalaVersion, String version) {
return lib + "_" + scalaVersion + ":" + version
}
dependencies {
play dependencyFor("com.typesafe.play:play-guice", scalaVersion, playVersion)
play dependencyFor("com.typesafe.play:play-logback", scalaVersion, playVersion)
play dependencyFor("com.typesafe.play:filters-helpers", scalaVersion, playVersion)
play dependencyFor("com.typesafe.play:play-java-jpa", scalaVersion, playVersion)
play "org.hibernate:hibernate-core:5.4.2.Final"
play "com.h2database:h2:1.4.197"
}
repositories {
jcenter()
maven {
name "lightbend-maven-releases"
url "https://repo.lightbend.com/lightbend/maven-release"
}
ivy {
name "lightbend-ivy-release"
url "https://repo.lightbend.com/lightbend/ivy-releases"
layout "ivy"
}
}
idea {
module {
sourceDirs += file("app")
testSourceDirs += file("test")
scopes.COMPILE = [plus: [configurations.play], minus: []]
scopes.RUNTIME = [plus: [configurations.playRun], minus: [configurations.play]]
scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
}
}
我正在使用
Java 8
,Gradle 5.4
,Play 2.6.7
最佳答案
现在,以下设置可以正常运行,并且需要一些技巧才能使其余依赖项正常运行。
plugins {
id 'play'
id 'idea'
}
# replace with
plugins {
id 'idea'
id 'org.gradle.playframework' version '0.9'
}
下一步是执行gradle idea
,您应该可以只导入文件夹和intellij。如果不是这种情况,请转至Build tools-> Gradle并选择use gradle
关于java - 获取Play框架可与Gradle和IntelliJ Idea一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57034079/