Xtext - 类型 com.google.inject.Inject 不在类路径中

Xtext - The type com.google.inject.Inject is not on the classpath

我在 JvmModelInferrer.xtend 中使用以下代码生成 Java class

@Inject extension JvmTypesBuilder

def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
    acceptor.accept(element.toClass(element.name)) [
        annotations += annotationRef(Inject);
    ]
}

当我尝试 运行 整个项目时,出现以下错误。

5226 [main] ERROR org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder  - Error initializing JvmElement
java.lang.IllegalArgumentException: The type com.google.inject.Inject is not on the classpath.
    at org.eclipse.xtext.xbase.jvmmodel.JvmAnnotationReferenceBuilder.annotationRef(JvmAnnotationReferenceBuilder.java:83)
    at org.eclipse.xtext.xbase.jvmmodel.JvmAnnotationReferenceBuilder.annotationRef(JvmAnnotationReferenceBuilder.java:60)
    at org.example.statemodel.jvmmodel.StatemodelJvmModelInferrer.lambda(StatemodelJvmModelInferrer.java:60)
    at org.example.statemodel.jvmmodel.StatemodelJvmModelInferrer$$Lambda/864303682.apply(Unknown Source)
    at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.initializeSafely(JvmTypesBuilder.java:206)
    at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toField(JvmTypesBuilder.java:588)

我尝试将相应的依赖项com.google.inject.source;bundle-version="3.0.0"添加到plugin.xml。我仍然遇到同样的错误。我们如何解决这个问题?

您必须确保 Guice 在包含您的 DSL 文件的项目的类路径中。