domingo, 27 de outubro de 2013

Basics of Maven

- Maven
                Features and goals:
                               - Simplify the build process, sharing JARs, publishing informations in a easy way.
                               - Deploy a system
                               - Manage Documentation, dependencies, releases, distribution, report
                               - Maven works on top of ANT
                                               Ant needs you to write the logic and provide de data
                                               Maven needs you to provide the data and know how to do most things.
                               - Maven has a local repository and well named jars, docs, etc.
                                               Provide a single location for downloads which versions are created automatically
                - POM (Project Object Model)
                              
                - Create a Project
                               Simple way:
                                                - mvn archetype:generate
                                                - There are over 850 archetypes.  Use the 314(
                                                -archetype-quickstart), sugested but maven
                                                - Version of maven-archetype-quickstart: Use the sugested(1.1), number 6.
                                                - groupId: The groupId that will be inside the pom.xml. I use: br.com.romalopes.meven2Test
                                                - artifactId: mavenToGradle.  The project will be created inside this directory.
                                                - Version: Accept the sugested.
                                                - Value for property papckage: The package that will be create inside the structure:br.com.romalopes.meven2Test
                                                - Confirm
                              
                               - A more sofisticated way
                                               - mvn archetype:generate -DgroupId=br.com.romalopes.maven2Test -DartifactId=maven-test -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
                It creates a structure like that:
                - my-app
                               |-- pom.xml
                               -- src
                                               |-- main
                                               |   `-- java.
                                               |       `-- com.
                                               |           `-- mycompany-
                                               |               `-- app
                                               |                   `-- App.java
                                               |-- resources
                                                              -- META-INF
                                                              -- application.properties   -->  InputStream is = getClass().getResourceAsStream( "/test.properties" );
                                               -- test
                                                               -- java
                                                                               -- com
                                                                                              -- mycompany
                                                                                                              -- app
                                                                                                                              -- AppTest.java
                - Phases to buil a project
                               Validate
                               generate-sources
                               process-sources
                               generate-resources
                               process-resources
                               compile
                               mvn package
                               integration-test
                               verify
                               install - install into the local repository
                               deploy - copies the final package to the remote repository
                               - others
                                               clean
                                               test
                                               dependency:copy-dependencies
                                               mvn site - generate a site for project documentation
                                               can call
                                                               mvn clean dependency:copy-dependencies package
                              
                - maven to Eclipse
                               Simple java
                                               mvn eclipse:eclipse
                               Dynamic Web Project
                                               mvn eclipse:eclipse -Dwtpversion=1.5
                                               In Eclipse:
                                                               Properties->Modify Project->Change Facet
                - plugins
                               To customize the build for a Maven Project
                                               
- Example

1:          <project xmlns="http://maven.apache.org/POM/4.0.0"  
2:           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
3:           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  
4:                               http://maven.apache.org/xsd/maven-4.0.0.xsd">  
5:           <modelVersion>4.0.0</modelVersion>  
6:           <groupId>com.mycompany.app</groupId>  
7:           <artifactId>my-app</artifactId>  
8:           <version>1.0-SNAPSHOT</version>  
9:           <packaging>jar</packaging>  
10:           <name>Maven Quick Start Archetype</name>  
11:           <url>http://maven.apache.org</url>  
12:           <dependencies>  
13:              <dependency>  
14:               <groupId>junit</groupId>  
15:               <artifactId>junit</artifactId>  
16:               <version>3.8.1</version>  
17:               <scope>test</scope>  
18:              </dependency>  
19:           </dependencies>  
20:           <build>  
21:              <resources>  
22:               <resource>  
23:                  <directory>src/main/resources</directory>  
24:                  <filtering>true</filtering>  
25:               </resource>  
26:              </resources>  
27:           </build>  
28:           <properties>  
29:              <my.filter.value>hello</my.filter.value>  
30:           </properties>  
31:          </project>      

Nenhum comentário:

Postar um comentário