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

查看:25
本文介绍了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 的插件和 中的 sbt 版本本身>project/build.properties 并将它们更新到最新版本(请咨询 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 命令来构建您的项目,请从 播放下载页面,提取并复制 sbt(如果您打算在 Linux 上构建它),sbt.bat(如果您打算在 Linux 上运行它)Windows) 和 sbt-dist 目录添加到您的项目中,并随时从您的项目中删除对 activator 的任何引用.尝试执行 ./sbt 并查看它是否有效.

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/.诅咒那些想出这些缓存名称及其路径的人.(提示:按住shift同时按delete将跳过回收站并永久删除文件.)尝试再次构建项目,希望现在一切正常.

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天全站免登陆