pom xml 中的依赖项和插件标记之间的 maven 有什么区别? [英] What is the difference in maven between dependency and plugin tags in pom xml?

查看:35
本文介绍了pom xml 中的依赖项和插件标记之间的 maven 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 maven 工具的新手,我用 Spring 和 Hibernate 创建了一个项目,它们在 pom.xml 中配置为插件,但 JUnit 被标记为依赖项.我的问题是一个作为插件和一个作为依赖背后的逻辑是什么?

I'm new to the maven tool, I have made a project with Spring and Hibernate and they are configured in pom.xml as plugins, but JUnit is tagged under dependency. My question is what is the logic behind one as a plugin and one as dependency ?

推荐答案

插件和依赖项都是 Jar 文件.

Both plugins and dependencies are Jar files.

但它们的区别在于,maven中的大部分工作都是使用插件完成的;而依赖只是一个 Jar 文件,它将在执行任务时添加到类路径中.

But the difference between them is, most of the work in maven is done using plugins; whereas dependency is just a Jar file which will be added to the classpath while executing the tasks.

例如,您使用编译器插件来编译 java 文件.您不能使用 compiler-plugin 作为依赖项,因为这只会将插件添加到类路径中,而不会触发任何编译.编译文件时要添加到类路径的 Jar 文件将被指定为依赖项.

For example, you use a compiler-plugin to compile the java files. You can't use compiler-plugin as a dependency since that will only add the plugin to the classpath, and will not trigger any compilation. The Jar files to be added to the classpath while compiling the file, will be specified as a dependency.

您的场景也是如此.您必须使用 spring-plugin 来执行一些 spring 可执行文件 [我不确定 spring-plugins 用于什么.我只是在这里猜测].但是您需要依赖项来执行这些可执行文件.Junit 被标记为依赖项,因为它被surefire-plugin 用于执行单元测试.

Same goes with your scenario. You have to use spring-plugin to execute some spring executables [ I'm not sure what spring-plugins are used for. I'm just taking a guess here ]. But you need dependencies to execute those executables. And Junit is tagged under dependency since it is used by surefire-plugin for executing unit-tests.

所以,我们可以说,插件是一个执行任务的Jar文件,依赖是一个提供类文件来执行任务的Jar.

So, we can say, plugin is a Jar file which executes the task, and dependency is a Jar which provides the class files to execute the task.

希望能回答您的问题!

这篇关于pom xml 中的依赖项和插件标记之间的 maven 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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