[英]Adding class to class path of sbt plugin
I am using an sbt
plugin to do some style checks on my code: https://github.com/sksamuel/sbt-scapegoat .我正在使用
sbt
插件对我的代码进行一些样式检查: https://github.com/sksamuel/sbt-scapegoat 。 On one of my projects, let's call this my-app, I added the sbt
plugin to the plugins.sbt
file inside the project directory.在我的一个项目中,我们称之为 my-app,我将
sbt
插件添加到项目目录中的plugins.sbt
文件中。
The tool runs fine and everything seems to work as expected.该工具运行良好,一切似乎都按预期工作。 This plugin has a compiler flag that allows for custom inspections to be passed in.
这个插件有一个编译器标志,允许传入自定义检查。
I therefore created another project, my-inspections
, in which I added a custom inspection using the same classes as the sbt
plugin.因此,我创建了另一个项目
my-inspections
,其中我使用与sbt
插件相同的类添加了自定义检查。 I then added my-inspections as an unmanaged jar in my-app.然后,我将 my-inspections 添加为 my-app 中的非托管 jar。 I did so by adding the following line to my
plugins.sbt
file:我通过在我的
plugins.sbt
文件中添加以下行来做到这一点:
unmanagedJars in Compile += {
Attributed.blank(file("lib/my-inspections.jar"))
}
Now, when I try to use the custom inspection class I added in my-inspections
and pass it to the provided compiler flag, I get an error saying it cannot find the class.现在,当我尝试使用我在
my-inspections
中添加的自定义检查 class 并将其传递给提供的编译器标志时,我收到一条错误消息,指出它找不到 class。 I passed in the fully qualified class name of the custom inspection I added.我通过了我添加的自定义检查的完全限定 class 名称。 The
sbt
plugin then does something like: sbt
插件然后执行以下操作:
Class.forName(inspection).getConstructor().newInstance().asInstanceOf[Inspection]
which causes a ClassNotFoundException
.这会导致
ClassNotFoundException
。
How can the sbt
plugin successfully load the Class
I created that has the custom inspection? sbt
插件如何成功加载我创建的具有自定义检查的Class
?
If you have the classes in a jar file, try putting the jar file in project/lib
.如果您在 jar 文件中有这些类,请尝试将 jar 文件放在
project/lib
中。 The project
directory is an sbt
build for your project; project
目录是为您的项目构建的sbt
; an sbt plugin belongs to the project build. sbt 插件属于项目构建。 The
lib
directory in project
is where you should be able to put unmanaged dependencies of the project. project
中的lib
目录是您应该能够放置项目的非托管依赖项的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.