龙目岛的Maven范围(编译与提供)

时间:2021-07-30 13:31:26

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.

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

        <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

但是当我将它设置为提供的范围时,我在单元测试中会遇到奇怪的行为。在尝试解决时,它们会与ClassNotFoundExceptions崩溃

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

Which maven scope is in general used for lombok?

哪个maven范围通常用于lombok?

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

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

2 个解决方案

#1


36  

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

应该在提供的范围内使用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.

原因(正如评论中所述)是lombok是一个仅编译时的工具。也就是说,它根本不需要在运行时。通过提供范围,可以使编译器可以使用lombok库,但它不是编译jar的依赖项。因此,您的最终jar将不依赖于Lombok,并且不需要包含在任何部署中,这样可以减少可部署的依赖性和大小。

#2


5  

Usually compile. provided is for jars that are usually shipped with the application server that will host the application. If you don't want the jar in the final application, it is maybe best to use the maven plugin rather than the jar directly: http://awhitford.github.io/lombok.maven/lombok-maven-plugin/index.html

通常编译。提供的是通常与将托管应用程序的应用程序服务器一起提供的jar。如果您不想在最终应用程序中使用jar,最好是直接使用maven插件而不是jar:http://awhitford.github.io/lombok.maven/lombok-maven-plugin/index。 HTML

#1


36  

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

应该在提供的范围内使用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.

原因(正如评论中所述)是lombok是一个仅编译时的工具。也就是说,它根本不需要在运行时。通过提供范围,可以使编译器可以使用lombok库,但它不是编译jar的依赖项。因此,您的最终jar将不依赖于Lombok,并且不需要包含在任何部署中,这样可以减少可部署的依赖性和大小。

#2


5  

Usually compile. provided is for jars that are usually shipped with the application server that will host the application. If you don't want the jar in the final application, it is maybe best to use the maven plugin rather than the jar directly: http://awhitford.github.io/lombok.maven/lombok-maven-plugin/index.html

通常编译。提供的是通常与将托管应用程序的应用程序服务器一起提供的jar。如果您不想在最终应用程序中使用jar,最好是直接使用maven插件而不是jar:http://awhitford.github.io/lombok.maven/lombok-maven-plugin/index。 HTML