1 © Luxoft Training 2012 Apache Maven introduction.

Презентация:



Advertisements
Похожие презентации
© Luxoft Training 2013 Annotations. © Luxoft Training 2013 Java reflection / RTTI // given the name of a class, get a "Class" object that // has all info.
Advertisements

© 2002 IBM Corporation Confidential | Date | Other Information, if necessary © Wind River Systems, released under EPL 1.0. All logos are TM of their respective.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Route Selection Using Policy Controls Applying Route-Maps as BGP Filters.
Loader Design Options Linkage Editors Dynamic Linking Bootstrap Loaders.
© 2005 Cisco Systems, Inc. All rights reserved.INTRO v Managing Your Network Environment Managing Cisco Devices.
© 2002 IBM Corporation Confidential | Date | Other Information, if necessary November 4, 2014 Copyright © 2006 Eclipse Foundation, Inc., Made available.
© 2006 Cisco Systems, Inc. All rights reserved.ISCW v IPsec VPNs Implementing the Cisco VPN Client.
© 2009 Avaya Inc. All rights reserved.1 Chapter Two, Voic Pro Components Module Two – Actions, Variables & Conditions.
© 2006 Cisco Systems, Inc. All rights reserved. MPLS v MPLS VPN Implementation Configuring VRF Tables.
Copyright ® 2000 MSC.Software Results S17-1 PAT301, Section 17, October 2003 SECTION 17 FILE MANAGEMENT.
© 2006 Cisco Systems, Inc. All rights reserved. SND v Configuring a Cisco IOS Firewall Configuring a Cisco IOS Firewall with the Cisco SDM Wizard.
Using Dreamweaver MX Slide 1 Window menu Manage Sites… Window menu Manage Sites… 2 2 Open Dreamweaver 1 1 Set up a website folder (1). Click New…
Evgeniy Krivosheev Andrey Stukalenko Vyacheslav Yakovenko Last update: Nov, 2013 Spring Framework Module 1 - Introduction.
© 2009 Avaya Inc. All rights reserved.1 Chapter Nine, Voic Pro in SCN Module Four – Distributed Voic Pro.
© 2006 Cisco Systems, Inc. All rights reserved. CIPT1 v Administration of Cisco Unified CallManager Release 5.0 Implementing Disaster Recovery.
© 2009 Avaya Inc. All rights reserved.1 Chapter Nine, Voic Pro in SCN Module Three – Backup Voic Pro.
Kurochkin I.I., Prun A.I. Institute for systems analysis of RAS Centre for grid-technologies and distributed computing GRID-2012, Dubna, Russia july.
Carousel from flshow.netflshow.net by Saverio CaminitiSaverio Caminiti.
© 2005 by IBM; made available under the EPL v1.0 | March 1, 2005 Tim deBoer Gorkem Ercan Extend WTP Server Tools for your.
USB Download Manual (v1.3) (GP2 Year 2010) LG Electronics/ LCD TV Division Feb. 17 th, Applied Models & Notice - File Copy - User Download Mode.
Транксрипт:

1 © Luxoft Training 2012 Apache Maven introduction

2 © Luxoft Training 2012 javac -classpath ~/work/projects/AntProject/lib/mysql.jar ~/work/projects/AntProject/src/* Why we need a build tool? To solve some standard build tasks like: Compile the sources Run JUnit tests Put results into folders Pack it Compile necessary resources for modules Deploy application to the server etc.

3 © Luxoft Training 2012 Tasks Building is a frequent, and its too Project Builders software to automate project build.

4 © Luxoft Training 2012 Project builders MAKE - C/C++ ANT - Java NANT -.NET MAVEN - Java SBT - Scala GRADLE - Java

5 © Luxoft Training 2012 ANT & MAVEN ANTMAVEN Doesnt have fixed folder structire or default behavior. Defaults-based. Many thinkgs are predefined. Knows where is the sources, where to put the compiled classes and has a default behavior. Imperative. We should say what to do and in what order to do, like in standard programming language. Declarative. All we need to do is to describe the final aim of the building. It will discover how to reach the aim itself. Doesnt have lifecycle. We have to define aims and dependencies. Fixed lifecycle. Defines strict phases of execution. Doesnt manage dependencies. Adding, deleting or updating of dependencies is manual. Manage dependencies. Adding, deleting or updating of dependencies is automatical. Doesnt need internet connection. Internet is necessary. Download plugins and libraries from internet.

6 © Luxoft Training 2012 MAVEN Installation You should check if java is installed: java version "1.6.0_21" Java(TM) SE Runtime Environment (build 1.6.0_21) Java HotSpot(TM) Client VM () Download and unpack the distributive: ~$ java -version

7 © Luxoft Training 2012 MAVEN in Windows configuration Configure PATH and M2_HOME variables PATH=...;%M2_HOME%\bin

8 © Luxoft Training 2012 MAVEN in Ubuntu ~$ mvn -version (-v) Apache Maven (rdebian-6) Java version: 1.6.0_26 Java home: /usr/lib/jvm/java-6-sun /jre Default locale: en_SG, platform encoding: UTF-8 OS name: "linux" version: " generic" arch: "i386" Family: "unix" ~$ sudo apt-get update Check the correcness of installation: ~$ sudo apt-get install maven3 ~$ sudo add-apt-repository ppa:natecarlson/maven3

9 © Luxoft Training 2012 Manual MAVEN installation (Linux) ~$ mvn -version (-v) Installation of Maven in Ubuntu: ~$ export M2=$M2_HOME/bin Check the correcness of installation: ~$ export PATH=$M2:$PATH ~$ export M2_HOME= You can add export commands to ~/.bash_profile to avoid configuring Maven again.

10 © Luxoft Training 2012 MAVEN configuration Level Description Project configuration 3 configuration levels: Configuration of all projects of the user Configuration of all users ~/.m2/settings.xml project/pom.xml {M2_HOME}/conf/settings.xml

11 © Luxoft Training 2012 Configure Proxy... optional true http proxyuser proxypass proxy.host.net 80 local.net|some.host.... To configure proxy add to settings.xml:

12 © Luxoft Training 2012 MAVEN folder apache-maven bin boot conf lib Running files Additional libraries Default configuration Launcher README LICENSE.txt

13 © Luxoft Training 2012 MAVEN components Maven Core - main principles and configuration. Plugins, to execute aims. Repository (local or remote). MAVEN has 3 main components:

14 © Luxoft Training 2012 Archetypes Archetype – plugin to generate project templates, which includes main folders and project configuration. com.vaadin:vaadin-archetype-clean:6.0.2 groupId artifactId version Example:

15 © Luxoft Training 2012 Archetypes vaadin-archetype- clean Archetypes examples: maven-archetype-quickstart maven-archetype-j2ee spring-mvc-archetype simple-gwt-webapp spring-osgi-bundle-archetype

16 © Luxoft Training 2012 Creating of the new project ~/projects$ mvn archetype:generate Choose archetype: 1: remote -> org.boretti.drools.integration:drools4-integration-helper-archetype (Support of the archetype for the Maven plugin) : remote -> sk.seges.sesam:sesam-annotation-archetype (-) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 209: 209 Choose version: 1.0 Define value for property 'groupId': ua.luxoft Define value for property 'artifactId': maven-training-project Define value for property 'version': 1.0-SNAPSHOT Define value for property 'package': ua.luxoft.maven.training [INFO] Parameter: groupId, Value: ua.ypitomets [INFO] Parameter: packageName, Value: ua.ypitomets [INFO] Parameter: package, Value: ua.ypitomets [INFO] Parameter: artifactId, Value: maven-research [INFO] Parameter: basedir, Value: /home/yura/work/research/maven [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] project created from Old (1.x) Archetype in dir: /home/yura/work/research/maven/maven-research [INFO] [INFO] BUILD SUCCESSFUL [INFO] [INFO] Total time: 1 minute 43 seconds [INFO] Finished at: Wed Aug 01 14:46:43 EEST 2012 [INFO] Final Memory: 14M/128M [INFO]

17 © Luxoft Training 2012 Creating of the new project ~/projects$ mvn archetype:create -DarchetypeGroupId= \ -DarchetypeArtifactId= \ -DarchetypeVersion= \ -DgroupId= \ -DartifactId= … alternate option Example: mvn archetype:create \ -DarchetypeGroupId=org.apache.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DarchetypeVersion=1.0 \ -DgroupId=org.example \ -DartifactId=simpleapp

18 © Luxoft Training 2012 ~/projects$ mvn compile [INFO] Scanning for projects... [INFO] [INFO] Building Maven Default Project [INFO] task-segment: [compile] [INFO] [ERROR] BUILD ERROR [INFO] [INFO] Cannot execute mojo: resources. It requires a project with an existing pom.xml, but the build is not using one. [INFO] [INFO] For more information, run Maven with the -e switch [INFO] [INFO] Total time: < 1 second [INFO] Finished at: Wed Aug 01 14:53:38 EEST 2012 [INFO] Final Memory: 2M/44M [INFO] How do you think what is the reason of the error? Creating of the new project

19 © Luxoft Training 2012 Creating of the new project [INFO] Scanning for projects... [INFO] [INFO] Building maven-research [INFO] task-segment: [compile] [INFO] [INFO] [resources:resources {execution: default-resources}] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /home/yura/work/research/maven/maven- research/src/main/resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Compiling 1 source file to /home/yura/work/research/maven/maven- research/target/classes [INFO] [INFO] BUILD SUCCESSFUL [INFO] [INFO] Total time: 3 seconds [INFO] Finished at: Wed Aug 01 15:06:11 EEST 2012 [INFO] Final Memory: 9M/81M [INFO] ~/projects/simpleapp$ mvn compile

20 © Luxoft Training 2012 Additionaly, its possible to set plugin parameter using prefix -DpropertyName=propertyValue. Examples: -Dfilter=spring List of archetypes will contain word spring -DarchetypeVersion=2.0 -Dgoals=clean,install Goals execution after project is created Archetypes version Creating of the new project

21 © Luxoft Training 2012 Archetypes creation (1st variant) ~/projects$ mvn archetype:create -DarchetypeArtifactId=maven-archetype-archetype -DgroupId=ua.luxoft.plugins -DartifactId=from-archetype-template ~/work/projects$ cd example && mvn eclipe:eclipse Creation of the new project: Go to the project folder

22 © Luxoft Training 2012 Archetypes :: Archetypes creation (Variant 1) Project contains 2 folders // HomeController.java package $package; import public class HomeController { … } Velocity Template Engine $groupId $artifactId $version $package

23 © Luxoft Training 2012 Archetypes creation (1 Variant) from-archetype-template src/main/java/HomeController.java src/main/resources/log4j.properties src/main/webapp/home.jsp src/main/webapp/WEB-INF/web.xml src/main/resources src/test/java src/main/java src/test/resources src/site

24 © Luxoft Training 2012 Archetypes creation (1 Variant) ~/projects/web-template$ mvn clean install ~/projects$ mvn archetype:create -DarchetypeGroupId=org.luxoft.plugins -DarchetypeArtifactId= from-archetype-template -DarchetypeVersion=1.0 -DgroupId=ua.luxoft.plugins -DartifactId=simple-project Add archetype to repository Creating project on the base of the new archetype

25 © Luxoft Training 2012 Archetypes creation (Variant 2) ~/projects/simplapp$ mvn archetype:create-from-project ~/projects/simplapp/target/generated-sources/archetype$ mvn clean install ~/projects/simplapp$ cd target/generated-sources/archetype Create the template on the base of the existing project Go to template folder Add to the repository

26 © Luxoft Training 2012 Floder structure *every default path may be changed by configuring the plugin pom.xmlConfiguration in the root folder of the project README.txt target/ src/main/java src/test/java Readme with the information about the project Folder for the output artefacts Standard folder for the source code of the application Standard folder for the source code of the tests src/test/resources Standard folder for the test resources src/main/configStandard folder for configuration files src/main/filters Standard folder for the filters src/main/resourcesStandard folder for project resources

27 © Luxoft Training 2012 Project build artefacts target classes com luxoft App.class maven-archiver pom.properties test-classes surefire-reports maven-research-1.0-SNAPSHOT.jar Test reports Root folder for the artefacts Project properties

28 © Luxoft Training 2012 POM structure POM

29 © Luxoft Training 2012 POM structure POM - Project Object Model POM-file contains the description of your project (declarative style!) and all specific configuration. XSD-schema:

30 © Luxoft Training 2012 POM structure Настройки окружения Coordinates Build DescriptionEnvironment

31 © Luxoft Training 2012 POM structure Minimal POM file should contain only model version and coordinates of the project com.luxoft.plugins minimum-pom 1.0-SNAPSHOT jar *by default packaging equals to jar Possible values for : pom, jar, maven-plugin, ejb, war, ear, rar, par.

32 © Luxoft Training 2012 POM file inheritance Every POM-file inherits super POM by default. Super POM: ${M2_HOME}/lib/maven uber.jar Super POM - virtual pom.xml inside Maven, which contains default configuration: - Central repository information (id = central) - File structure in the field build - Default versions of frequently used plugins org/apache/maven/project/pom xml ~$ mvn help:effective-pom To look at the resulting pom file:

33 © Luxoft Training 2012 POM file inheritance Iheritance allows to get rid of duplicating Example: Let we have several projects, all of which are using log4j library for logging com.luxoft-maven parent 1.0-SNAPSHOT pom log4j Build project: $ mvn install ru.apache_maven testproj1 1.0-SNAPSHOT com.apache_maven parent 1.0-SNAPSHOT jar Use inheritance in new project:Original project:

34 © Luxoft Training 2012 Multi-module Maven project When create module its necessary to set parent project. Parent project must have packaging=pom All commands executed on parent project will be executed on child project at first.

35 © Luxoft Training 2012 Example ua.luxoft.plugins multimodule 1.0-SNAPSHOT pom core api ui Every subproject will have parent element. JEMHI jehmi-core src/main/java pom.xml jehmi-api src/main/java pom.xml jehmi-ui src/main/java pom.xml Multi module Maven project

36 © Luxoft Training 2012 Dependencies Maven is automatically downloading and add necessary library versions to the classpath. junit test Example of the dependency declaration: test runtime provided compile system

37 © Luxoft Training 2012 Dependencies Versions management in the dependencies Version is preferable (2.5.4, 2.5.9) [2.5.4,2.5.9] [,2.5.9] Any version inside the range Any version including from range including and Any vesion up to [2.5.5] Only version

38 © Luxoft Training 2012 Conflicts resolution org.hibernate hibernate ga javax.transaction jta *remove the dependency

39 © Luxoft Training 2012 Visualization Hierarchy list of dependencies: Dependencies analysis (search for unused): Alphabetic list of dependencies: Extract dependencies to some folder: ~/maven-project$ mvn dependency:tree ~/maven-project$ mvn dependency:resolve ~/maven-project$ mvn dependency:unpack ~/maven-project$ mvn dependency:analyze

40 © Luxoft Training 2012 Properties pom.xml allows to use properties to avoid duplicate values Property types: Properties pom in file: ${project.*} Predefined properties settings.*, env.*, System.getProperty() Properties, defined in the external file Access to properties is performed with use of ${...}

41 © Luxoft Training 2012 Properties POM properties are defined with tag... /tmp ${temp.directory} Example:

42 © Luxoft Training 2012 Properties in POM RELEASE org.springframework spring-orm ${spring.version} org.springframework spring-aop ${spring.version} org.springframework spring-web ${spring.version} Example:

43 © Luxoft Training 2012 Getting property value To check the property value use goal evaluate in plugin maven-help-plugin $ mvn help:evaluate [INFO] Searching repository for plugin with prefix: 'help'. [INFO] [INFO] Building maven-research [INFO] task-segment: [help:evaluate] (aggregator-style) [INFO] [INFO] [help:evaluate {execution: default-cli}] [INFO] No artifact parameter specified, using 'ua.ypitomets:maven- research:jar:1.0-SNAPSHOT' as project. [INFO] Enter the Maven expression i.e. ${project.groupId} or 0 to exit?: ${project.version} [INFO] 1.0-SNAPSHOT ${project.url} [INFO] ${java.io.tmpdir} [INFO]/tmp

44 © Luxoft Training 2012 System properties To review all system properties you can use plugin maven-help-plugin, goal system. $ mvn help:system ============================================================================ System Properties ============================================================================ java.runtime.name=Java(TM) SE Runtime Environment sun.boot.library.path=/usr/lib/jvm/java-6-sun /jre/lib/i386 java.vm.version=20.1-b ============================================================================ Environment Variables ============================================================================ COMPIZ_CONFIG_PROFILE=ubuntu DISPLAY=:0 SSH_AUTH_SOCK=/tmp/keyring-i5CTfv/ssh UBUNTU_MENUPROXY=libappmenu.so LESSOPEN=| /usr/bin/lesspipe %s...

45 © Luxoft Training 2012 Project lifecycle

46 © Luxoft Training 2012 Project lifecycle Built-in build lifecycles: 1) clean 2) site 3) default

47 © Luxoft Training 2012 Project lifecycle A Build Lifecycle is Made Up of Phases A Build Phase is Made Up of Plugin Goals

48 © Luxoft Training 2012 Project lifecycle A plugin goal represents a specific task (finer than a build phase) which contributes to the building and managing of a project. A goal not bound to any build phase could be executed outside of the build lifecycle by direct invocation. The order of execution depends on the order in which the goal(s) and the build phase(s) are invoked. Goal – the task to be executed to get project to the next stage mvn clean dependency:copy-dependencies package

49 © Luxoft Training 2012 Project lifecycle validate compile test package integration test verify install deploy validate Initialize generate-sources process-sources generate-resources process-resources compile process-classes post-process generate-test-sources process-test-sources generate-test-resources process-test-resources test-compile process-test-classes test prepare-package package pre-integration-test integration-test post-integration-test verify install deploy Default: pre-clean clean post-clean pre-site site post-site Clean: Site: site-deploy

50 © Luxoft Training 2012 Profiles Profile – a custom Maven configuration for special cases. Profile has configuration which will be added to the main configuration or will replace it. Profiles are used to implement platform independency. Different profiles will lead to different build results.

51 © Luxoft Training 2012 Profile scopes 3 profiles scope Project scope – profiles defined in POM file User scope – profiles defined in settings.xml in user directory (%USER_HOME/.m2/settings.xml) Global scope – profiles defined in settings.xml in Maven directory (%M3_HOME/.m2/settings.xml)

52 © Luxoft Training 2012 Profiles activation Ways to activate profiles Explicitely – using key -P mvn groupId:artifactId:goal -P p1,p2 Using Maven configuration – tag... p1 p3... By checking of the files – tag target/generated-sources/axistools/wsdl2java/org/apache/maven target/generated-sources/axistsools/src...

53 © Luxoft Training 2012 Profiles activation Ways to activate profiles: - System configuration Windows XP Windows x Existing of properties debug... mvn groupId:artifactId:goal -Denvironment=test

54 © Luxoft Training 2012 Profiles activation Parameters of the environment 1.4 [1.3,1.6) --> Profiles deactivation ~$ mvn groupId:artifactId:goal -P !profile-1,!profile-2 Ways to activate profiles

55 © Luxoft Training 2012 Profiles declaration has the same tags as tag (1) development localhost org.hsqldb hsqldb (2) productionServer not a localhost postgresql jdbc Example

56 © Luxoft Training 2012 Check of the active profile You can find out the active profile by using command: ~$ mvn help:active-profiles [INFO] There are no active profiles. ИЛИ [INFO] The following profiles are active: - appServerConfig (source: settings.xml) >mvn help:active-profiles -P appserverConfig-dev [INFO]The following profiles are active: ИЛИ [INFO] The following profiles are active: -appServerConfig-def (source: pom.xml) - appServerConfig (source: settings.xml) - appServerConfig-def (source: pom.xml)

57 © Luxoft Training 2012 Plugins Plugin attaching org.apache.maven.plugins maven-checkstyle-plugin 2.6 package check Plugin – set of several goals

58 © Luxoft Training 2012 Plugin configuration org.codehaus.mojo tomcat-maven-plugin 1.1 false test-server configuration tag contains the specific plugin configuration

59 © Luxoft Training 2012 Plugin configuration org.apache.maven.plugins maven-antrun-plugin 1.2 org.apache.ant ant maven-ant-plugin v1.2 use version of ant, to use the latest version we should add it to configuration in

60 © Luxoft Training 2012 Plugin configuration... org.apache.maven.plugins maven-antrun-plugin 1.2 false Default plugin configuration is inherited from Super POM, To avoid it its necessary to use tag

61 © Luxoft Training 2012 Frequently used plugins

62 © Luxoft Training 2012 Help Contatins the list of goals to get additional information ArtifactID:maven-help-plugin Goal prefix: help Goal:Description: Shows the list of project profiles. Shows the list of project profiles which are active for this build active-profiles all-profiles Shows the list of project attributes describe effective-pom Shows the resulting POM-file evaluate Evaluate property in interactive mode system Shouws the list of system properties

63 © Luxoft Training 2012 Archetype Plugin generates the project templates, including the folder structure and configuration. Goal prefix: archetype ArtifactID: maven-archetype-plugin Goal:Description: сreate Finds archetype by groupId and artifactId. Used to create the new project. create-from-project generate jar Create the project on the base of existing project. Generate new project in interactive mode. update-local-catalog Creates jar-file from existing archetype Update the local catalog

64 © Luxoft Training 2012 Compiler Plugin compiles the source code and tests in Java. Attached to phase: compile ArtifactID:maven-compiler-plugin Goal prefix:compiler Goal:Description: compile Compiles the source code testCompile Compile the source code of tests

65 © Luxoft Training 2012 Compiler org.apache.maven.plugins maven-compiler-plugin UTF-8 Example of plugin configuration: Compiler – major plugin used in almost any project. Its available by default, but usually need to be configurated.

66 © Luxoft Training 2012 Compiler Some usefule configutation parameters verbose true or false fork true or false executable path to javac compilerVersion compiler version meminitial maxmem debug true or false compilerArgument compilerArguments compilerId groovy-eclipse-compiler optimize true or false Maximal size of memory

67 © Luxoft Training 2012 Source Plugin creates jar file with the project sources ArtifactID: maven-source-plugin Goal prefix:source Goal:Description: aggregate Build all sources to the single project jar Build all sources to single jar. test-jar Build all test sources to single jar.

68 © Luxoft Training 2012 Source org.apache.maven.plugins maven-source-plugin attach-sources verify jar Example of configuration: Useful parameters: inlcudePom Should POM-file be added to archive. finalName Name of the generated archive. includes What sources should be included. excludes What sources should be excluded.

69 © Luxoft Training 2012 Jar Creates jar file with classes. ArtifactID: maven-jar-plugin Goal prefix:jar Goal:Description: jar Creates jar-file from the project. sign Sign jar archive using Jarsigner sign-verify Checks signature using Jarsigner test-jar Creates jar-file from project tests.

70 © Luxoft Training 2012 Jar org.apache.maven.plugins maven-jar-plugin com.someclass.Main com.someclass Example of configuration Useful parameters skipIfEmpty Skip creation if jar is empty. verbose Verbose logging. finalName Name of the resulting archive.

71 © Luxoft Training 2012 Javadoc Plugin allows to perform javadoc documentation generation. ArtifactID: Goal prefix:javadoc maven-javadoc-plugin Goal:Description: jar Pack documentation into jar archive. javadoc Generate documentation with the standard Javadoc utility. test-jar Pack test documentation into jar archive. fix Fix documentation in the source code

72 © Luxoft Training 2012 Javadoc Example of Javadoc configuration in POM-file: org.apache.maven.plugins maven-javadoc-plugin 2.5 UTF-8 true public 1.5 ${basedir}/src/main/java/a/b/c/foo -inferrel -inferdep -quiet -hide java.* -collpackages java.util.* -qualify -postfixpackage -nodefontsize 9 -nodefontpackagesize 7

73 © Luxoft Training 2012 Exec Plugin allows to start system and java applications ArtifactID: Goal prefix:exec exec-maven-plugin Parameters: - exec.args Send parameters of application execution - exec.outputFile File for standard output - mainClass Main class of Java application Goal:Description: exec Execution of external applications java Execution ofjava applications

74 © Luxoft Training 2012 exec Example of plugin configuration in POM-file: org.codehaus.mojo exec-maven-plugin java com.harman.jehmi.JEHMIUpdater /home/ypitomets/ /home/ypitomets/work/

75 © Luxoft Training 2012 Site Plugin allows to generate site with the project description ArtifactID: Goal prefix:site maven-site-plugin Useful parameters: - outputDirectory Folder for generated site - generateSitemap Should map of site be generated (sitemap.html) - chmod Change rights for a site. Goal:Description: jar Pack site to the archive for later use deploy Deployment of the site run Running site on the local machine by using Jetty site Creating site which describes the project

76 © Luxoft Training 2012 Site... org.apache.maven.plugins maven-site-plugin {basedir}/target/site/tempdir... Plugin configuration in POM file: Plugin is easely configurable, its possible to add pages, menu items, etc.

77 © Luxoft Training 2012 Site src/site/site.xml – XML descriptor.

78 © Luxoft Training 2012 Antrun Allows to execute ant scripts. *All Maven properties are accessible for ant tasks ArtifactID: Goal prefix: antrun maven-antrun-plugin Useful parameters target XML to describe Ant goals. exportAntProperties Export Ant property to Maven Goal:Description: run Execution of ant task.

79 © Luxoft Training 2012 Antrun maven-antrun-plugin 1.6 run Configuring plugin in POM file:

80 © Luxoft Training 2012 Checkstyle Plugin checks style and quality of the source code Based on project checkstyle.sourceforge.net/. ArtifactID: Goal prefix:checkstyle maven-checkstyle-plugin Полезные параметры: - consoleOutput Print errors to console - exludes/includes Include/exclude files. - configLocation Path to configuration file (config/sun_checks.xml) Goal:Description: check Check the code. Shows the amount of code incorrectness and print it to console. checkstyle Make a check of the code and generate the reports.

81 © Luxoft Training 2012 Checkstyle org.apache.maven.plugins maven-checkstyle-plugin 2.6 src/config/checkstyle.xml true package check Configuring plugin in POM file: Most often used checks - existing of comments - size of class not more than N lines - not empty catch block in try-catch construction. - used Sysout instead of LOG.error

82 © Luxoft Training 2012 Useful plugins maven-docck-plugin maven-pdf-plugin Documentation analysys Pdf documentation generation maven-release-plugin Creating of releases maven-eclipse-plugin maven-idea-plugin Creating files for Eclipse Creating files for Idea maven-javacc-plugin Files generation maven-native-plugin Compiling C and C++ code maven-sql-pluginExecution of SQL scripts maven-taglist-plugin Report on the base of tags maven-licence-plugin License management

83 © Luxoft Training 2012 Useful plugins maven-download-plugin maven-android-plugin Files download For android applications maven-java-formatter-plugin Check code format maven-twitter-plugin maven-jetty-plugin Setting Twitter status Running Jetty …. And so on maven-bundle-plugin Create plugin for OSGI maven-jira-pluginJira plugin

84 © Luxoft Training 2012 Repositories – storage of artifacts and libraries. ~/.m2/repository Both repositories have the same folder structure. 2 types: Local Local repository path: Remote Repositories

85 © Luxoft Training 2012 Installation from repository is performed on creating project from archetype or resolving dependency. By default Maven is using repository with ID=central. Repositories:: central repository

86 © Luxoft Training UK UK Central central... Using mirrors allows to redefine repository Repositories:: central repository :: Mirror

87 © Luxoft Training my-internal-site Internal repository is usualy created on the level oа company or on the level of company subdivision. Supported protocols: SCP, SFTP, FTP, WebDAV or file system. Repositories:: internal repository

88 © Luxoft Training 2012 Why to add a library to the internal repository? 1. Library is not presented in the remote repositories 2. Internal library. ~/work/projects$ mvn install:install-file -Dfile=~/kaptcha-{version}.jar \ -DartifactId=kaptcha \ -DgroupId=com.google.code \ -Dversion={version} \ -Dpackaging=jar com.google.code kaptcha 2.3 Repositories:: internal repository

89 © Luxoft Training true... Execution of Maven in offline mode: use key -о Example: mvn install -o mvn test -o Repositories:: Work in offline mode

90 © Luxoft Training 2012 maven.atlassian.com/repository/public The Atlassian public repo. repository.codehaus.org Codehaus releases repository google-maven-repository.googlecode.com/svn/repository Google's open source releases gradle.artifactoryonline.com/gradle/libs Gradle libraries download.java.net/maven/2 java.net Maven2 Format download.java.net/maven/1 java.net Maven1 format repository.apache.org repository.jboss.org/maven2 JBoss Release Repository snapshots.jboss.org/maven2 JBoss Snapshot Repository repo.jfrog.org/artifactory/libs-releases JFrog libs releases repo.terracotta.org/maven2 Terracotta releases repo.jfrog.org/artifactory/plugins-releases-local JFrog plugins releases repo.jfrog.org/artifactory/repo1 Maven Repo1 Cache proxy nexus.openqa.org/content/repositories/releases OpenQA (Selenium) release download.oracle.com/maven Oracle releases repo1.maven.org/maven2 Central maven repository scala-tools.org/repo Scala-Tools.org releases maven.springframework.org/milestone SpringSource bundles maven.springframework.org/release Spri ngSource releases maven.springframework.org/snapshot SpringSource snapshots repository.springsource.com/maven/bundles/release SpringSource EBR el4.elca-services.ch/el4j/maven2repository ELCA Maven plugins eviware.com/repository/maven2/ SOAPUI Maven plugins Repositories:: Useful repositories

91 © Luxoft Training 2012 File New Other filter Eclipse download Plugin installation / Eclipse integration

92 © Luxoft Training 2012 Allows to select a profile The most simple project architecture (used if architecture was not selected) mvn eclipse:eclipse (.classpath,.project) Eclipse integration

93 © Luxoft Training 2012 Entering of project coordinates Poperties will be available in the moment of build and can be used in any place of POM file Name of the root package of project Eclipse integration

94 © Luxoft Training 2012 File Import Eclipse integration

95 © Luxoft Training 2012 Name of the root package from configuration Eclipse integration

96 © Luxoft Training 2012 Continuous integration Hudson Jenkins Cruise controll etc. Continuous Integration (CI) is the practice in software engineering of perfoming frequent automized builds to quicker findinng the potential integration problems.

97 © Luxoft Training 2012 Its necessary to download Hudson.war и and execute on server. Server execution:./catalina.sh run Continuous integration

98 © Luxoft Training 2012 Creating the new task To configure a new task we should write: Source of the source code (CVS, Subversion, git) When the build should be performed What actions should be performed (reports, archivation, etc.) Continuous integration

99 © Luxoft Training 2012