Play!2.x构建导致sbt失败,并出现NoClassDefFoundError [英] Play!2.x build results in sbt failing with NoClassDefFoundError

查看:99
本文介绍了Play!2.x构建导致sbt失败,并出现NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新了IDE,插件版本和库依赖关系,现在无法构建我的项目. SBT在执行时抛出java.lang.NoClassDefFoundError: sbt/TrackLevel.我也无法运行./sbt clean,因为它试图加载项目并失败并出现相同的错误.

I have just updated the IDE, plugin version and library dependencies, and now I can't build my project. SBT throws java.lang.NoClassDefFoundError: sbt/TrackLevel when executed. I also can't run ./sbt clean since it attempts to load the project and fails with the same error.

推荐答案

这可能由于各种原因而发生,通常是由于某些版本不匹配或剩余的缓存所致.令人惊讶的是,sbt经常无法优雅地处理更新插件,更不用说本身了,这就是我每次决定刷新项目并提高版本时都浪费时间的原因.

That can happen for various reasons, usually because of some mismatched versions or leftover caches. Surprisingly often, sbt can't gracefully handle updating plugins, let alone itself and it's the reason I waste hours every time I decide to refresh my project and bump up versions.

以防万一.请注意刚刚更新的插件/相关性,以及其更改日志中是否提到了任何内容.在尝试1时,请记住这一点.

You know, just in case. Pay attention to the plugin/dependency you've just updated and whether anything is mentioned in its changelog. Keep this in mind while going through the Attempt 1.

这是一个更新所有(其他)依赖项和插件的好机会(当然,如果这不会破坏您的项目,但是除非您已经在使用不赞成使用的方法,否则不应该这样).这样做可能会解决此问题,因此,请在build.sbt中查找您所引用的库依赖关系,project/plugins.sbt中的插件以及project/build.properties中的sbt版本本身,并将其更新为最新版本(请咨询Google和相应的存储库,例如 http://mvnrepository.com ).

This is a good chance to update all (other) dependencies and plugins (of course, if that doesn't break your project but it shouldn't be the case unless you're already using deprecated methods). Doing so might resolve the issue, so look up library dependencies you're referencing in your build.sbt, plugins from project/plugins.sbt and sbt version itself in project/build.properties and bring them up to their latest versions (consult Google and appropriate repositories, e.g. http://mvnrepository.com).

如果您仍在使用activatorplay命令来构建项目,请从

If you're still using activator or play commands to build your project, grab the Java/Scala seed or one of the templates from Play donwload page, extract and copy sbt (if you intend building it on Linux), sbt.bat (if you intend running it on Windows) and sbt-dist directory into your project and feel free to delete any references to activator from your project. Try executing ./sbt and see if it works.

由于您仍在阅读本文,因此更新依赖关系的机会并没有真正发挥作用.好吧,至少现在您有了一个刷新的项目.

Since you're still reading this, chances are updating dependencies didn't really do the job. Well, at least now you have a refreshed project.

删除target/.删除project/target/.删除project/project/target/.诅咒任何想出这些缓存名称及其路径的人. (提示:在按住Delete键的同时按住shift键将跳过回收站并永久删除文件.)尝试再次构建该项目,希望现在一切正常.

Remove target/. Remove project/target/. Remove project/project/target/. Curse whomever came up with those cache names and their paths. (Protip: holding shift while hitting delete will skip the recycle bin and delete the files permanently.) Attempt to built the project again and hope everything is okay now.

万一它没有完成任务,作为最后的手段,我们将删除所有缓存并重新开始.如果先前失败的构建遗漏了某些内容,请重复步骤2.

In case it didn't do the job, as a last resort we're gonna remove all the caches and start fresh. Repeat step 2 in case previous failed build left something behind.

导航到您的主文件夹.删除.ivy和/或.ivy2.删除.sbt,或者如果它包含某些配置,您要保留将其重命名为例如.sbt.old并随后还原特定文件.由于这些目录可能包含成千上万个文件,因此可能需要一段时间. (您可以在此处删除所有IDE缓存,但我从未遇到过这个问题-无论如何,它会在下次启动时重建整个项目,因为您已经销毁了大部分依赖它的东西)

Navigate to your home folder. Remove .ivy and/or .ivy2. Remove .sbt, or in case it contains some configuration you want to retain rename it to e.g. .sbt.old and restore specific files afterwards. It could take a while since those directories could contain dozens of thousands of files. (You could delete all IDE caches here, but I've never encountered that being the issue - it will rebuild the whole project on next launch anyway since you've destroyed most of which it relies on already)

返回您的项目文件夹,然后重新运行./sbt.这可能需要几分钟,因为它将下载所有依赖项(包括sbt和Play本身)并将它们放置到位.之后,您将获得一个新项目,就好像您是在干净的机器上从源代码构建它一样.

Go back to your project folder and rerun ./sbt. That could take a few minutes since it will download all dependencies (including sbt and Play themselves) and put them in place. After that, you will have fresh project, as if you've build it from source on a clean machine.

万一它仍然无法正常工作,您可以放心地认为它是构建文件中的错误(请再次对其进行三次检查)或构建系统中的错误.

In case it still doesn't work, you can safely assume it's either mistake in your build files (triple check them again) or a bug in the build system.

这篇关于Play!2.x构建导致sbt失败,并出现NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆