Scala Play应用程序遇到了一些问题,该应用程序依赖于使用Gradle部署到本地Maven存储库的Java库。我已经设置了一个测试项目,其中包含一个包含一个类的简单Gradle Java模块,以及一个使用此类的简单Scala Play项目。 Java类看起来像:
public class TestClass {
public String testMethod(){
return "Some content we will change later.";
}
}
使用build.gradle设置将JAR部署到本地Maven仓库:
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = 1.7
project.group = 'play-update-maven-snapshot'
version = '1.0-SNAPSHOT'
运行gradle install
会将JAR放入本地仓库:
$ ls ~/.m2/repository/play-update-maven-snapshot/gradle-java/1.0-SNAPSHOT/
gradle-java-1.0-SNAPSHOT.jar maven-metadata-local.xml
gradle-java-1.0-SNAPSHOT.pom
在Scala / Play / SBT端,build.properties更新为:
sbt.version=0.13.1
选择https://github.com/sbt/sbt/issues/321中注明的更改。
根据当前的SBT文档配置build.sbt,从本地Maven存储库中获取工件:
name := "play-scala"
version := "1.0-SNAPSHOT"
resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache
)
libraryDependencies+= "play-update-maven-snapshot" % "gradle-java" % "1.0-SNAPSHOT"
play.Project.playScalaSettings
Application.scala更新为:
package controllers
import play.api.mvc._
object Application extends Controller {
def index = Action {
Ok(views.html.index(new TestClass().testMethod()))
}
}
还有一个被黑客攻击的index.scala.html来简单地显示传递给它的内容:
@(message: String)
@main("Welcome to Play") {
message
}
我们有简单的测试环境。开始播放不会显示任何依赖性错误:
$ play run
[info] Loading project definition from /<redacted>/play-update-maven-snapshot/play-scala/project
[info] Set current project to play-scala (in build file:/<redacted>/play-update-maven-snapshot/play-scala/)
[info] Updating {file:/<redacted>/play-update-maven-snapshot/play-scala/}play-scala...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
--- (Running the application from SBT, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
访问localhost:9000不幸的是给出了这个:
[info] Compiling 5 Scala sources and 1 Java source to /<redacted>/play-update-maven-snapshot/play-scala/target/scala-2.10/classes...
[error] /<redacted>/play-update-maven-snapshot/play-scala/app/controllers/Application.scala:8: not found: type TestClass
[error] Ok(views.html.index(new TestClass().testMethod()))
感觉这可能与旧的SBT / Ivy缓存本地SNAPSHOTs问题有关,如上所述。但是,使用rm -Rf ~/.ivy2/cache/play-update-maven-snapshot
删除常春藤缓存似乎无能为力。
任何指针都将非常感激。这里有一个GitHub项目源:https://github.com/timfulmer/play-update-maven-snapshot。
修改1:
确保JAR实际上是本地回购:
$ ls -n ~/.m2/repository/play-update-maven-snapshot/gradle-java/1.0-SNAPSHOT/gradle-java-1.0-SNAPSHOT.jar
-rw-r--r-- 1 501 20 634 Feb 4 11:53 /Users/<redacted>/.m2/repository/play-update-maven-snapshot/gradle-java/1.0-SNAPSHOT/gradle-java-1.0-SNAPSHOT.jar
从
更新了build.sbtresolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
到
resolvers += Resolver.mavenLocal
仍然没有快乐。
编辑2:
非常绝望:)。
$ jar xvf ~/.m2/repository/play-update-maven-snapshot/gradle-java/1.0-SNAPSHOT/gradle-java-1.0-SNAPSHOT.jar
created: META-INF/
inflated: META-INF/MANIFEST.MF
inflated: TestClass.class
$ cat ./TestClass.class
????3
<init>()VCodeLineNumberTableLocalVariableTablethis
LTestClass;
testMethod()Ljava/lang/String;
SourceFileTestClass.java
"Some content we will change later.
TestClassjava/lang/Object!/*??
看起来像本地Maven回购的一切都是正确的。
谢谢,
- 蒂姆
答案 0 :(得分:2)
Dunno如果这是早期版本的堆栈的问题,但是在最近的一个具有完全相同设置的项目中,我没有再遇到这个问题。当时感觉路径中的某些内容在设置错误后会被缓存。
小心按照最新版本给出的顺序执行上述步骤似乎让一切都快乐。
如果您遇到此问题,请参阅上述评论中的建议。 Aditya Pawade对于讨厌的文件可能隐藏的地方有一些想法。
干杯,
- 蒂姆