How do you configure a Maven plugin in the pom.xml file?

How do you configure a Maven plugin in the pom.xml file?

A) By adding a <plugin> element within the <build> section
B) By adding a <dependency> element within the <dependencies> section
C) By adding a <repository> element within the <repositories> section
D) By adding a <plugin> element within the <dependencyManagement> section

Answer:

A) By adding a <plugin> element within the <build> section

Explanation:

To configure a Maven plugin, you add a <plugin> element within the <build> section of the pom.xml file. Plugins extend the functionality of Maven and can be used to perform various tasks during the build process, such as compiling code, packaging, and running tests.

For example:


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

In this example, the Maven Compiler Plugin is configured to use Java 8 for compiling the project.

Reference links:

https://www.javaguides.net/p/maven.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top