Tuesday, November 12, 2013

What is Maven

Overview

Developing a software  system doesn't means just writing codes. It may be set of code lines for simple program but when we go for large application development we have to think beyond that. When developing java applications some important tasks have to considered.
  1. Your java project may depend on lot of external jars.  
  2. When adding different jars you have to search them with correct version.
  3. Project will consist of different components(modules). 
  4. All these components have to be compiled  and test individually.
  5. Most software projects cannot be developed at once as usual bugs in runtime environments and client requirements.So versions has to be add time to time and build them with adding new dependencies.
  6. Software projects are developed by group of engineers so when manually adding dependencies conflict can be happen.
  7. You have add documentations too.
  8. Some components may share same jar so downloading same thing different time may waste more resources.

Apache Maven


Solution  for these considerations is the project management tool. There are many project management tools available in the computer society. Apache Maven is well known project management tool for java project. It is base on simple concept called Project Object model (POM ) .Ant,make are some other tools used to manage project build process.

POM

POM is not a big thing just a XML documents with predefined elements set. You can add dependency jars, repositories, plugins, sub modules with those definitions.


   4.0.0
   org.maven.sample
   myapp-customer
   myyapp
   1.2-SNAPSHOT
   jar
    
   ..


Some common POM elements are,
root of the descriptor
     version of project descriptor this POM conforms. 
     The location of the parent project, if one exists.
          The group id of the parent project to inherit from. 
          artifact id of the parent project to inherit from. 
          The version of the parent project to inherit. 
      The relative path of the parent pom.xml file within the check out.     
     

     unique identifier for a project. (eg. org.apache.maven) 
     identifier for this artifact that is unique within the group given by the group ID. name of the jar without version                                
     The current version of the artifact produced by this project.
     The type of artifact this project produces, for example jar war ear pom.default is jar 
      The full name of the project. 
      A detailed description of the project, used by Maven whenever it needs to describe theproject, such as on the      web site. 
      The URL to the project's homepage. 
   
         The modules (sometimes called subprojects) to build as a part of this project.                                                 Each module listed is a relative path to the directory containing the module.
          
          
     
     Properties that can be used throughout the POM as a substitution, and are used as filters in resources if enabled. The format is value.
     
     declare dependency versions, exclusions and other things that let you manage them in place (e.g. a parent pom) for multiple projects
     
     declare the actual need of a dependency and if the dependency is managed in a parent pom you can do so without using a version and it will be inherited and therefore be consisted across you usages downstream of the the parent pom
          
          
     
      remote repositories for discovering dependencies and extensions.
          
          
     
     lists of the remote repositories for discovering plugins for builds and reports.
          
          
     

      Build Information required to build the project. 
     A listing of project-local build profiles which will modify the build process when activated.
          
                
     

Repositories

Maven repository is used to hold build artifacts and dependencies of varying types. There are two types of repositories.

Local
Copy your own installation. Maven identify the dependencies specified in dependency element and download them to your local repository .Another module can use that dependency(ex.jar) without downloading again.Default is .m2
Linux- Home/.m2 
Windows-Documents/.m2)

Remote
used for hold the released artifacts. Once you ready for the release you can deploy your packages(jars) to remote repository for share with others.

Basic Operations

  1. You can defined modules within POM. Each module will also contain sub modules. each module will have own POMs. 
  2. build order will be defined by maven based on dependencies of each module. It will create structure called dependency tree during build process. Think your POM have <module>A</module><module>B</module><module>C</module> .If A depend on B build order would be B ,A,C .build will fail when we have dependency conflicts(cyclic dependency).
  3. You can run tests with each module with maven test plugins. As an example think you are building upload module. you can write basic test class with JUNIT to upload file to your component. Then run it when building the component.
  4. Maven has different phases like validating the project is correct,compile modules,test ,package them to distributed format like jars,deploy in environment where integration test an be run verify on criteria.
  5. Install phase install the package into the local repository and deploy phase will copy the final package to the remote repository for sharing purposes.
  6. Additional Clean phase will clean the caches and artifacts in previous builds and site phase will publish documentation site for project.
For more information

No comments :

Post a Comment