简体   繁体   English

使用Buildship在Gradle中实现项目依赖

[英]Gradle Project Dependencies in Eclipse with Buildship

I use Eclipse Mars.2 (4.5.2) with Buildship 1.0.14. 我在Buildship 1.0.14中使用Eclipse Mars.2(4.5.2)。 Gradle version is 2.12. Gradle版本为2.12。

I import my gradle project into the Eclipse. 我将gradle项目导入Eclipse。 No .project or .classpath files exist before import. 导入之前不.project.classpath文件。 All modules imported successfully. 所有模块已成功导入。 But almost every project with java code has missed dependencies and showing red "X". 但是几乎每个带有Java代码的项目都缺少依赖项,并显示红色的“ X”。

If you open a java file with error, you can see that Eclipse can't resolve the import. 如果打开错误的Java文件,则可以看到Eclipse无法解决导入。 But if you open imported class by name, it can find it in the other module's dependency. 但是,如果您按名称打开导入的类,则可以在其他模块的依赖项中找到它。

Gradle -> Refresh project doesn't help. Gradle->刷新项目无济于事。

The necessary dependencies declared in the root build.gradle in this way: 以这种方式在root build.gradle中声明了必要的依赖项:

ext.library = [
    swagger: [
            [ group: "io.swagger", name: "swagger-annotations", version: "1.5.3" ],
            [ group: "io.swagger", name: "swagger-core", version: "1.5.3" ],
            [ group: "io.swagger", name: "swagger-jaxrs", version: "1.5.3" ]
    ]
]

and in the modules I declare it like this: 在模块中我这样声明:

dependencies {
    providedCompile library.swagger
}

When you execute gradle build from command line or even from Eclipse, the build is successful. 从命令行甚至从Eclipse执行gradle build ,构建成功。

The small project example to reproduce this problem can be found on github (thank to RaGe for participating in that). 可以在github上找到重现此问题的小项目示例(感谢RaGe的参与)。

Could you help me to resolve this issue with Eclipse? 您能帮我用Eclipse解决此问题吗?

Answering with reference to the code sample you provided here . 参考您在此处提供的代码示例进行回答。

You're not using the war plugin, but instead declaring your own custom configuration called providedCompile . 您没有使用war插件,而是声明了自己的自定义配置,称为providedCompile Gradle and by extension, buildship/eclipse don't know what providedCompile means. 摇篮推而广之,buildship /月食不知道什么providedCompile手段。 So the dependencies you listed in providedCompile are not being used as compile time dependencies. 因此,您在providedCompile中列出的依赖项不会被用作编译时依赖项。

It follows that your import statements become compile time errors - both in eclipse and from gradle commandline with gradle build 因此,您的import语句将成为编译时错误-在eclipse中和使用gradle build gradle命令行中

You can add providedCompile to the compile classpath by doing: 您可以添加providedCompile做的编译类路径:

sourceSets.main.compileClasspath += [configurations.providedCompile]

If you also add the eclipse plugin to your project, you can modify eclipse compile class path with: 如果还将eclipse插件添加到项目中,则可以使用以下命令修改eclipse编译类路径:

eclipse {
  classpath {
    plusConfigurations += [configurations.providedCompile]
  }
}

官方错误跟踪器上的人告诉我,在gradle 2.12中,现在可以使用compileOnly范围,默认情况下,该范围也已连接到Eclipse。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM