Exclude dependency in maven

We can exclude dependency in maven by using the exclusion element. <project> … <dependencies> <dependency> <groupId>test.ProjectTest1</groupId> <artifactId>Project-Test1</artifactId> <version>1.0</version> <scope>compile</scope> <exclusions> //Declare the exclusion here <exclusion> <groupId>test.ProjectTest2</groupId> <artifactId>Project-Test2</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </project><project> … <dependencies> <dependency> <groupId>test.ProjectTest1</groupId> <artifactId>Project-Test1</artifactId> <version>1.0</version> <scope>compile</scope> <exclusions> //Declare the exclusion here <exclusion> <groupId>test.ProjectTest2</groupId> <artifactId>Project-Test2</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </project>

Build maven project offline

Steps to build maven project offline. Open the the project that you want to build offline. Run the following command: mvn dependency: go -offline See the output. Run the following command: mvn -o clean package Build is successfully completed offline.

How profiles are specified in maven?

Maven build profiles provides the facility to build project using different configurations. We can just specify a profile with the different build configuration and build the project with this build profile when needed. Profiles are specified using a subset of the elements available in the POM itself.

Archetype in maven

Archetype is a Maven plugin which is used to create a project structure as per its template. Example: Maven-archetype-webapp

Types of maven plugins

Maven plugin types: Build Plugins Reporting Plugins Build Plugins: Build plugins are executed at the build time. Build plugins should be declared inside the element. Reporting Plugins: Reporting plugins are executed at site generation time. Reporting plugins should be declared inside the element.

What is maven plugin used for?

A maven plugin represents a set of goals which provides the facility to add your own actions to the build process. Syntax to execute a plugin: mvn [plugin–name]:[goal–name] Maven plugins can be used to: create jar file. create war file. compile code files. unit testing of code. create project documentation. create project reports.

Remote repository in maven

Maven remote repository is a repository on a web server. A remote repository can be located anywhere on the internet or inside a local network. We can configure a remote repository in the POM file. We have to put the following XML elements right after the element: <repositories> <repository> <id>w3schools.code</id> <url>https://maven.w3schools.com/maven2/lib</url> </repository> </repositories><repositories> <repository> <id>w3schools.code</id> <url>https://maven.w3schools.com/maven2/lib</url> … Read more

Central repository in maven

Maven central repository is created by the apache maven community itself. It contains a lot of commonly used libraries. By default Maven looks in this central repository for any dependencies needed but not found in your local repository. Maven central repository path: http://repo1.maven.org/maven2/.

Local repository in maven

Maven local repository is a directory on the developer’s machine. It gets created when we run any maven command for the first time. It contain all the dependencies (downloaded by maven) like library jars, plugin jars etc. Default location of maven local repository is user-home/.m2 directory. We can change the default location of maven local … Read more

Explain Maven repository search order

Maven repositories are directories of packaged JAR files with extra meta-data. The meta-data is represented by POM files. A repository contains all the project jars, library jar, plugins and any other project specific artifacts. Maven repository search order Local repository then Central repository then Remote repository. Note: Maven stops processing and throws an error if … Read more