Gradle + PlayFramework:无法解析源依赖
Gradle + PlayFramework: Cannot resolve sources dependency
我在 Gradle 2.7 中使用新的 Play Framework 支持。
具有讽刺意味的是,Play 2.3.x 明确依赖于 org.scala-sbt:io:0.13.8
。
如果我添加 ,Gradle 能够从 typesafe 的存储库中解析 JAR(不是源代码,只是 类)
model {
components {
play {
platform play: "2.3.7", scala: "2.10", java: "1.7"
}
}
}
repositories {
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 group: "org.scala-sbt", name: "io", version: "0.13.8", classifier: "jar", configuration: "compile"
}
但是它似乎无法解析 io-sources.jar
。我明白了:
FAILURE: Build failed with an exception.
- 出了什么问题:
任务“:runPlayBinary”执行失败。
Could not find io-sources.jar (org.scala-sbt:io:0.13.8).
Searched in the following locations:
https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/io/0.13.8/srcs/io.jar
我其实并不关心这些来源,我只是想在运行 gradlew runPlay
时避免这个运行时异常
Execution exception
[RuntimeException: java.lang.NoClassDefFoundError: sbt/Path$]
有什么建议吗?我似乎无法弄清楚如何排除或解决源依赖性。
我 运行 与 Play 2.4 和 Gradle 2.7 进入相同的 RuntimeException (NoClassDefFound sbt/Path$)。在我的例子中,根本问题是没有正确定义所有存储库(不包括 typesafe-ivy -> sbt-io 没有解决 -> 认为我需要声明 sbt-io-dependency -> 错误的 sbt-io 导致提到异常...)。
我建议您将 jcenter() 添加为存储库,删除对 sbt 的显式依赖并在 build.gradle 中说明播放版本。例如我的工作 gradle.build:
plugins {
id 'play'
}
dependencies {
repositories {
jcenter()
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"
}
}
play 'com.typesafe.play:play-jdbc_2.11:2.4.3'
[...other dependencies - but not "org.scala-sbt"!]
}
model {
components {
play {
platform play: '2.4.3', scala: '2.11'
injectedRoutesGenerator = true
}
}
}
在你的情况下,最后一部分应该是:
model {
components {
play {
platform play: '2.3.7', scala: '2.10'
}
}
}
一位 Gradle 开发者在 Gradle forums
上回答了我的问题
TL;DR - Gradle/Play 2.3.7 特有的错误,可以使用
解决
repositories {
ivy {
url "https://repo.typesafe.com/typesafe/ivy-releases/"
layout "pattern", {
ivy "[organisation]/[module]/[revision]/ivys/ivy.xml"
artifact "[organisation]/[module]/[revision]/jars/[artifact].[ext]"
}
}
}
就我而言,升级到 Play 2.3.9 解决了我的问题。
我在 Gradle 2.7 中使用新的 Play Framework 支持。
具有讽刺意味的是,Play 2.3.x 明确依赖于 org.scala-sbt:io:0.13.8
。
Gradle 能够从 typesafe 的存储库中解析 JAR(不是源代码,只是 类)
model {
components {
play {
platform play: "2.3.7", scala: "2.10", java: "1.7"
}
}
}
repositories {
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 group: "org.scala-sbt", name: "io", version: "0.13.8", classifier: "jar", configuration: "compile"
}
但是它似乎无法解析 io-sources.jar
。我明白了:
FAILURE: Build failed with an exception.
- 出了什么问题:
任务“:runPlayBinary”执行失败。
Could not find io-sources.jar (org.scala-sbt:io:0.13.8). Searched in the following locations: https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/io/0.13.8/srcs/io.jar
我其实并不关心这些来源,我只是想在运行 gradlew runPlay
Execution exception [RuntimeException: java.lang.NoClassDefFoundError: sbt/Path$]
有什么建议吗?我似乎无法弄清楚如何排除或解决源依赖性。
我 运行 与 Play 2.4 和 Gradle 2.7 进入相同的 RuntimeException (NoClassDefFound sbt/Path$)。在我的例子中,根本问题是没有正确定义所有存储库(不包括 typesafe-ivy -> sbt-io 没有解决 -> 认为我需要声明 sbt-io-dependency -> 错误的 sbt-io 导致提到异常...)。
我建议您将 jcenter() 添加为存储库,删除对 sbt 的显式依赖并在 build.gradle 中说明播放版本。例如我的工作 gradle.build:
plugins {
id 'play'
}
dependencies {
repositories {
jcenter()
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"
}
}
play 'com.typesafe.play:play-jdbc_2.11:2.4.3'
[...other dependencies - but not "org.scala-sbt"!]
}
model {
components {
play {
platform play: '2.4.3', scala: '2.11'
injectedRoutesGenerator = true
}
}
}
在你的情况下,最后一部分应该是:
model {
components {
play {
platform play: '2.3.7', scala: '2.10'
}
}
}
一位 Gradle 开发者在 Gradle forums
上回答了我的问题TL;DR - Gradle/Play 2.3.7 特有的错误,可以使用
解决repositories {
ivy {
url "https://repo.typesafe.com/typesafe/ivy-releases/"
layout "pattern", {
ivy "[organisation]/[module]/[revision]/ivys/ivy.xml"
artifact "[organisation]/[module]/[revision]/jars/[artifact].[ext]"
}
}
}
就我而言,升级到 Play 2.3.9 解决了我的问题。