Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Composer vs Maven

Pawel Dyrek
November 02, 2018

Composer vs Maven

Comparison of popular application-level package management systems. In my presentation, I will describe basic assumptions of both systems, and how to use them.

Pawel Dyrek

November 02, 2018
Tweet

More Decks by Pawel Dyrek

Other Decks in Programming

Transcript

  1. What they are? Both are tools designed for project management,

    to keep all dependencies together. Prepared to standarize way of project building and clarify definition what project consists of. Written to make developers life a bit easier. Composer vs Maven
  2. Maven Designed for Java-based projects. Several goals were attempted while

    desiginig: Making the build process easy Providing a uniform build system Providing quality project information Providing guidelines for best practices development Allowing transparent migration to new features Composer vs Maven
  3. Maven – project initiation mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

    Basic project structure generated by maven: my-app |-- pom.xml `-- src |-- main | `-- java | `-- com | `-- mycompany | `-- app | `-- App.java `-- test `-- java `-- com `-- mycompany `-- app `-- AppTest.java Composer vs Maven
  4. 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.mycompany.app</groupId> <artifactId>my-app</artifactId>

    <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Maven Quick Start Archetype</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> </dependencies> </project> Composer vs Maven
  5. Maven tools validate: validate the project is correct and all

    necessary information is available compile: compile the source code of the project test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed package: take the compiled code and package it in its distributable format, such as a JAR. integration-test: process and deploy the package if necessary into an environment where integration tests can be run verify: run any checks to verify the package is valid and meets quality criteria install: install the package into the local repository, for use as a dependency in other projects locally deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. clean: cleans up artifacts created by prior builds site: generates site documentation for this project Composer vs Maven
  6. Composer Composer is a tool for dependency management in PHP.

    It allows you to declare the dependent libraries your project needs and it will install them in your project for you. Composer was designed to solve several typical issues: You have a project that depends on a number of libraries. Some of those libraries depend on other libraries. You declare the things you depend on. Composer finds out which versions of which packages need to be installed, and installs them (meaning it downloads them into your project). Composer vs Maven
  7. composer.phar This is a composer itself, to download execute simple

    command: curl -sS https://getcomposer.org/installer | php This is a standalone php script, nothing is needed else to be installed, it will also keep itself up to date (will notify if requires update). Composer vs Maven
  8. composer.json Only file that developer works on while using composer,

    this file describes the dependencies of your project and may contain other metadata as well. Most common key in composer.json file is „require” used to describe dependencies: { "require": { "monolog/monolog": "1.0.*" } } Composer vs Maven
  9. composer.json Other examples of keys are metadata keys like authors

    or license: "authors": { "name": "Nils Adermann", "email": "[email protected]", "homepage": "http://www.naderman.de", "role": "Developer" }, "license": [ "LGPL-2.1", "GPL-3.0+" ] Composer vs Maven
  10. composer.json – package versions Exact version 1.0.2 Range >=1.0 >=1.0,<2.0

    >=1.0,<1.1 | >=1.2 Wildcard 1.0.* Next Significant Release ~1.2 equivalent to >=1.2,<2.0 Composer prefers stable releases by default, however it can be overwritten: 1.0.*@dev It is a valid version number – composer will also look for dev packages. Composer vs Maven
  11. Composer install After developer declared all dependencies and other needed

    information in composer.json file, all needed to be done is executing single command: $ php composer.phar install Which will install all dependencies to „vendor” directory, and create composer.lock file. Composer vs Maven
  12. composer.lock After installing the dependencies, composer writes the list of

    the exact versions it installed, into a composer.lock file. This locks the project to those specific versions. Lock file should be added to repository – when „install” command is executed, composer first looks for lock file, if found, it will install exectly same versions of each library, this will ensure same libraries on every environment as developer designed. Composer vs Maven
  13. composer update Installing dependencies when lock file exists keeps libraries

    exactly on desired version. When newer version of any library was published we should execute php composer.phar update command, which will download newest versions of libraries according to composer.json file, and update lock file. Also specific library can by updated – is we want to update only specific package we should execute: php composer.phar update package_name Composer vs Maven
  14. Package list All packages available via composer are listed on

    packagist.org site, if any package other than posted on that site is needed, we can specify other repositiories to be checked for packages: "repositories": [ { "type": "vcs", "url": "https://github.com/Seldaek/monolog" }, { "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/" } ... Composer vs Maven
  15. Jenkins integration Both of those tools can be integrated with

    continuous integration tools like Jenkins or Hudson which will automatically build our project on different environments. Usage of composer or maven will ensure that we will have project built in exectly same way on every environment, and with same dependency package set. Composer vs Maven