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

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

问题描述

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

解决方案

插件和依赖都是Jar文件。



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



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



与您的方案相同。你必须使用spring-plugin来执行一些spring的可执行文件[我不知道用什么spring-plugins。我只是在这里猜测]。但是您需要依赖来执行这些可执行文件。并且Junit被标记为依赖,因为它由surefire-plugin用于执行单元测试。



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



希望能回答您的问题!


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 ?

解决方案

Both plugins and dependencies are Jar files.

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.

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.

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.

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.

Hope that answers your question!

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

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