且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

pom xml 中的依赖项和插件标记之间的 maven 有什么区别?

更新时间:2022-05-31 01:53:46

插件和依赖项都是 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.

希望能回答您的问题!