GithubHelp home page GithubHelp logo

maven's Introduction

Maven

What is Maven?

  • Maven is a build automation tool used primarily for Java projects.
  • It addresses two aspects of building software: first, it describes how software is built, and second, it describes its dependencies.

Why Use Maven?

  • Simplifies the build process: Maven uses a standardized project structure and a consistent build process.
  • Dependency Management: Automatically downloads and manages project dependencies from central repositories.
  • Reproducible Builds: Ensures consistent build results across different environments.
  • Easy Integration: Works seamlessly with various IDEs and CI/CD tools.
  • Extensibility: Can be extended with plugins to perform a variety of tasks.

Need for Maven

  • Efficient Project Management: Organizes project structure and simplifies build lifecycle.
  • Dependency Management: Handles dependencies, reducing conflicts and ensuring compatibility.
  • Consistent Builds: Provides a standard way to build projects, ensuring consistency across development teams.
  • Simplifies Project Configuration: Uses a simple XML file (pom.xml) to manage project configurations.
  • Community Support: Extensive community and plugin support for various needs and integrations.

Maven Build Lifecycle Commands

1. clean

  • Command: mvn clean
  • Explanation: Removes all files generated by the previous build, ensuring a fresh start for the next build process.

2. validate

  • Command: mvn validate
  • Explanation: Checks if the project is correct and all necessary information is available. This phase ensures that the project is in a valid state before proceeding to the next phases.

3. compile

  • Command: mvn compile
  • Explanation: Compiles the source code of the project.

4. test

  • Command: mvn test
  • Explanation: Runs the tests using a suitable unit testing framework. The tests should be located in the src/test/java directory.

5. package

  • Command: mvn package
  • Explanation: Packages the compiled code into a distributable format, such as a JAR or WAR file.

6. verify

  • Command: mvn verify
  • Explanation: Runs any checks to verify the project is valid and meets quality standards.

7. install

  • Command: mvn install
  • Explanation: Installs the package into the local repository, making it available for other projects on the same machine.

8. deploy

  • Command: mvn deploy
  • Explanation: Copies the final package to the remote repository for sharing with other developers and projects.

Example Commands

  • To clean and build the project: mvn clean install
  • To compile and run tests: mvn compile test

pom.xml

The pom.xml file is the heart of a Maven project, managing dependencies, plugins, and project configurations.

Key Elements of pom.xml:

  • groupId: Defines the group or organization that the project belongs to. It follows the standard Java package naming rules (e.g., com.example).
  • artifactId: A unique name to identify the project (e.g., my-project).

Example pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.anshulmaventutorial</groupId>
  <artifactId>FirstMavenProject</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>FirstMavenProject</name>
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

maven's People

Contributors

anshulraigh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.