![](/img/trans.png)
[英]unable to add maven compiler and surefire plugin in the existing pom.xml
[英]In pom.xml can we keep maven-compiler-plugin and maven-surefire-plugin under a dependency tag instead of plugin tag?
在为 Selenium 创建 maven 项目时,我通常将 maven-compiler-plugin 和 maven-surefire-plugin 放在 plugin 标签下,如下所示:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-beta-4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.4.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
但是我在 maven central repo 中看到了对它们的依赖
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</dependency>
那么我们可以将这些作为依赖项而不是插件吗?
Maven 中央仓库。 仅向您显示 groupId、artifactId 和它的版本。 但是在您的情况下,您必须在构建中使用它们并提供配置。 因此,简而言之,您的问题的答案是否定的。
依赖标签只是声明依赖,但插件在项目构建中有更多的工作要做。 详情参考https://maven.apache.org/guides/introduction/introduction-to-plugins.html
这取决于您是要将它们用作插件还是依赖项。
通常,它们用作插件,在您的 Selenium 项目中也应该如此。
但是,如果您正在编写代码并想要导入插件 jar 中的类,那么您可以将它们用作依赖项 - 我想情况并非如此,因此如果需要,请将它们用作插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.