如何让Gradle将Lombok添加到其项目和外部依赖库? [英] How to make Gradle add Lombok to its Project and external dependencies libraries?

查看:1025
本文介绍了如何让Gradle将Lombok添加到其项目和外部依赖库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse Neon中创建了一个Java项目。我使用Buildship 1.0.21将项目导入为Gradle项目,并运行 wrapper init 命令来生成生成,设置和包装文件。

该项目有一个空的源文件夹,因为我正试图解决一个更复杂的项目类似的问题,并采取分而治之的方法 - 只需添加Lombok依赖项。



这是我的 build.gradle 按照lombok网站的指示:

  apply plugin:'java'

dependencies {
compileOnlyorg.projectlombok:lombok:1.16 .12

gradle-wrapper.properties 如果需要:

  distributionBase = GRADLE_USER_HOME 
distributionPath =包装/ dists
zipStoreBase = GRADLE_USER_HOME
zipStorePath = wrapper / dists
distributionUrl = https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip / *< ---试过其他版本太* /

然后我运行jar文件将其安装在我的eclipse上。如果我通过Java Build Path手动添加jar,它可以工作,但我希望Gradle为我处理这个问题。当我刷新项目时什么也没有发生 - 项目和外部依赖项下没有lombok jar,依赖lombok的代码会出错。



还有另一个项目它确实有它,我不知道我做了什么不同,但我知道这是可能的。

解决方案

我设法解决这是经过试验和错误。 build.gradle 文件必须添加 jcenter 存储库:

 存储库{
jcenter()
}

为什么会出现这种情况,为什么在我不知道的地方没有提到这一点。但现在这是有效的。


I created a Java project in Eclipse Neon. I used Buildship 1.0.21 to import the project as a Gradle project and ran the wrapper and init commands to generate the build, settings and wrapper files.

The project has an empty source folder because I am trying to solve a similar problem on a more complicated project and taking the divide and conquer approach - just add Lombok dependency.

Here is my build.gradle as instructed on the lombok website:

apply plugin: 'java'

dependencies {
    compileOnly "org.projectlombok:lombok:1.16.12"
}

and gradle-wrapper.properties if needed:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip /* <--- tried other versions too */

and I ran the jar file to install it on my eclipse. If I add the jar manually via "Java Build Path" it works but I want Gradle to handle this for me. When I refresh the project nothing happens - there is no lombok jar under "Projects and External Dependencies" and code relying on lombok will give errors.

There is another project I have which does have it there and I don't know what I did differently but I know it's possible.

解决方案

I managed to solve this after trial and error. The build.gradle file must add the jcenter repository:

repositories {
    jcenter()
}

Why this is the case and why this is not mentioned anywhere I don't know. But for now this is what works.

这篇关于如何让Gradle将Lombok添加到其项目和外部依赖库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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