1 / 112

Building better software with Maven & Sonar

Building better software with Maven & Sonar. By Rohit Ghatol. About Me. For Java. Build Tool. Reporting Tool. What is Maven?. Software Distribution. Project Management. Maven Quick Demo. Requirements for Maven. JDK 6+ Maven 2.x.

hera
Download Presentation

Building better software with Maven & Sonar

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building better software with Maven & Sonar By Rohit Ghatol

  2. About Me

  3. For Java Build Tool Reporting Tool What is Maven? Software Distribution Project Management

  4. Maven Quick Demo

  5. Requirements for Maven • JDK 6+ • Maven 2.x

  6. mvnarchetype:generate-DarchetypeArtifactId=maven-archetype-quickstart-DinteractiveMode=false-DgroupId=com.mycompany.app-DartifactId=my-app

  7. Directory Structure com/mycompany/app/App.java com/mycompany/app/AppTest.java

  8. mvn install

  9. Directory Structure

  10. Maven Directory Structure Directory NameDescription src/main/java Application/Library sources src/main/resourcesApplication/Library resources src/main/filters Resource filter files src/main/assembly Assembly descriptors src/main/configConfiguration files src/main/webappWeb application sources src/test/javaTest sources src/test/resourcesTest resources src/test/filters Test resource filter files src/siteSite LICENSE.txtProject's license NOTICE.txtNotices and attributions required by libraries that the project depends on README.txtProject's readme

  11. Why Maven?

  12. But Ma, I have Ant?

  13. Project Dependency in Ant C:\project1 C:\project2 Project 1 Project 2 I only need Project 1, but I still need to checkout Project 2 C:\Project2\dist Build.xml Build.xml Using Relative Path

  14. Checking in Dependencies Snapshot builds Project 1 Project 2 Project 3 libs libs libs • project2.jar • servlet-api.jar • project3.jar • commons.jar • logging.jar • hamcrest.jar 3rd Party Dependencies are checked in! What about CIT?

  15. Convention Vs Configuration Almost Every one is doing following? Is it Time to define a HighLevel Lifecyle ? Clean Prepare Compile Jar Test

  16. Custom Ant Tasks Build Cycle Project 1 Clean libs When to call the task Life cycle? Compile • project2.jar • servlet-api.jar • android-build.jar Jar Dex APT What about Reuse? What about Distribution?

  17. Reporting Test Run Report Code Coverage Report PMD Can I get these by default? FindBugs Change Log ……

  18. Software Distribution Maven Spring Repo Repo Repo1 Repo2 Repo2 Repo Xyz.. Synerzip Project1 Internet Project2 Project3

  19. Going Deeper into Maven

  20. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=”….> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>my-app</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>

  21. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=”….> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>my-app</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>

  22. Understanding Repositories Synerzip Central Proxy/Internal Repo mvn package mvn install ~/.m2/repository mvn deploy Maven Project Download needed dependencies e.gjunit Install the artifact in to local repository (~/.m2/repository Push artifact to Internal/Central repository

  23. Maven Architecture Plugins Core Maven Core compile jar surefire … … • Parsing Maven XML File • Maven LifeCycle • Basic Plugins compile jar test …. ….

  24. Maven Concepts Goals LifeCycle mvnarchetype:generate mvn install mvn <<Plugin>>:<<Goal>> mvn <<LifeCycle Phase>>

  25. Maven Plugins & Goals Plugin Goals compiler jar surefire jar test-jar sign Sign-verify compile testCompile test Command: mvnhelp:describe –Dplugin:jar

  26. Maven LifeCycle Phases Goals process-resources resources:resources compile compiler:compile process-classes process-test-resources resources:testResources test-compile compiler:testCompile test surefire:test prepare-package package jar:jar

  27. mvn clean install • maven-clean-plugin:2.4.1:clean • maven-resources-plugin:2.4.3:resources • maven-compiler-plugin:2.3.2:compile • maven-resources-plugin:2.4.3:testResources • maven-compiler-plugin:2.3.2:testCompile • maven-surefire-plugin:2.7.2:test • maven-jar-plugin:2.3.1:jar • maven-install-plugin:2.3.1:install

  28. Standalone Maven Project

  29. Effective POM

  30. Make Changes • Add Employee Model Class • Add Employee Service (Use Map for persistence) • Add Employee Test Cases • Add Reporting Plugins to generate site

  31. Maven Site Generation

  32. Maven Reporting <reporting> <plugins> <!-- surefire-reports --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.6</version> </plugin> <!-- JavaDocPlugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.8</version> </plugin> <!-- jxrsource code browsing plugin --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jxr-maven-plugin</artifactId> <version>2.0-beta-1</version> </plugin> </reporting>

  33. Maven Site

  34. Maven Site

  35. Maven Site

  36. Maven Site

  37. Maven Site

  38. Maven Site

  39. Maven Site

  40. Maven Site

  41. Maven Web App Project

More Related