龙目岛的Maven范围(编译与提供) [英] Maven Scope for Lombok (Compile vs. Provided)

查看:107
本文介绍了龙目岛的Maven范围(编译与提供)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现lombok.jar最终出现在我们的最终工件中,这不是必需的.以我的理解,lombok只是编译时.

I recently found out that the lombok.jar ends up in our final artifact, which shouldn't be necessary. In my understanding lombok is compile-time only.

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.14.4</version>
        </dependency>

但是当我将其设置为提供的范围时,在单元测试中会出现奇怪的行为.尝试解析

But when I set it to scope provided, I get strange behaviour in unit tests. They crash with ClassNotFoundExceptions then when trying to resolve

java.lang.NoClassDefFoundError: com/svv/esp/serviceimpl/dataimport/common/validation/LongValidator

龙目岛通常使用哪个Maven范围?

Which maven scope is in general used for lombok?

我在MacOSX 10.9上使用Oracle JDK build 1.8.0_25-b17

I'm using Oracle JDK build 1.8.0_25-b17 on MacOSX 10.9

推荐答案

Lombok应该在provided范围内使用(请参见

Lombok should be used at the provided scope (see the official docs).

原因(如评论中所述)是lombok是仅编译时工具.也就是说,在运行时完全不需要.通过将作用域设置为provided,可以使Lombok库可用于编译器,但它不是与已编译jar的依赖关系.这样,您最终的jar将不再依赖Lombok,并且不需要将其包含在任何部署中,从而减少了可部署项的依赖性和大小.

The reason (as has been stated in the comments) is that lombok is a compile-time-only tool. That is, it is not needed at runtime at all. By making the scope provided, you make the lombok libraries available to the compiler but it is not a dependency of your compiled jar. As such, your final jar will not depend on Lombok and it does not need to be included in any deployment, which reduces the dependencies and size of your deployables.

这篇关于龙目岛的Maven范围(编译与提供)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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