[英]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.