40
1 Confidential and propriety Galil Software, Ltd. + - Raed Awad & Salah Kabbani

A quick guide on how to work with Maven and Git

Embed Size (px)

Citation preview

1Confidential and propriety Galil Software, Ltd.

+ - Raed Awad & Salah Kabbani

2Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

3Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

What is a project management tool ?

o Build automation is the act of scripting or automating a wide variety of tasks that software developers do in their day-to-day activities including things like:

• compiling computer source code into binary code• packaging binary code• running automated tests• deploying to production systems• creating documentation and/or release notes

4Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

• Folder Structure • POM File Basics• Dependencies• Plugins• Maven Repository• Eclipse Integration

5Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Folder Structure

6Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Folder Stucure - src/main/what?

• src/main/java • target • pom.xml

7Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Folder Stucure - src/main/java

• Where we store our Java code The beginning of our package declaration

com.yourcompanyname.division

• What about other languages src/main/groovy

• What about testing src/test/java

8Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Folder Stucure - target

• Where everything gets compiled to • Also where tests get ran from • Contents in this directory get packaged into a jar, war, ear,

etc…

9Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

POM File Basics

10Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

pom.xml

11Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

pom.xml

Can be divided into 4 basic parts:

o Project Information • groupId • artifactId • version • packaging

o Dependencies • Direct dependencies used in our application

o Build • Plugins • Directory Structure

o Repositories • Where we download the artifacts from

12Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Dependencies

13Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Dependencies

o What we want to use in our application o Dependencies are imported by their naming convention

• Often considered the most confusing part of Maven

o We have to know the groupId, artifactId, and the version of what we are looking for

o Added to a dependencies section to our pom file

14Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Dependencies o Just list the dependency that we want

• Transitive dependencies will be pulled in by Maven

o Need at a minimum 3 things: • groupId • artifactId • version

15Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

pom.xml with our new dependency

16Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Plugins

17Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Goals

o The default goals are plugins configured in the maven install • clean, compile, test, package, install, deploy

o Super pom has these goals defined in it, which are added to your effective pom:

18Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Goals

• clean : Deletes the target directory and any generated resources

• compile : Compiles all source code, generates any files, copies resources to our classes directory

• package : Runs the compile command first, runs any tests, packages the app based off of its packaging type

• install : Runs the package command and then installs it in your local repo

• deploy : Runs the install command and then deploys it to a corporate repo Often confused with deploying to a web server

• test : Test the compiled source code

19Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Compiler Plugin

o Used to compile code and test code o http://maven.apache.org/plugins/maven-compiler-plugin/index.html o Invokes Javac, but with the classpath set from the dependencies o Defaults to Java 1.5 regardless of what JDK is installed o Configuration section allows customization

• Includes/Excludes • Fork • Memory • Source/target

20Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

JSystem Maven Plugin

o This method can be easier for integrating JSystem with CI systems and would result less resource consumption.

o Configuring the Plugin :

o Executing the Plugin :

21Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Maven Repository

22Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Local Repo

o Where Maven stores everything it downloads • Installs in your home directory\.m2

• C:\Users\<yourusername>\.m2\repository

o Stores artifacts using the information that you provided for artifactId, groupId, and version

• C:\Users\<yourusername>\.m2\repository\commons-lang\commons-lang\2.1\commons-lang-2.1.jar

o Avoids duplication by copying it in every project and storing it in your SCM

23Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Repositories

o Simply just a http accessible location that you download files from

o Super pom.xml• Default with the Maven installation

o Default location• http://repo.maven.apache.org/maven2

o Multiple repositories allowed

o Corporate Repository• Nexus (this is what the default repo is built on)• Artifactory

24Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

• Artifactory fully supports working with Maven both as a source for artifacts needed for a build, and as a target to deploy artifacts generated in the build process.

• To configure Maven to resolve artifacts through Artifactory you need to modify the settings.xml.

25Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

• To deploy build artifacts through Artifactory you must add a deployment element with the URL of a target local repository to which you want to deploy your artifacts.

• To update build artifacts through Artifactory you must add a repositiory configuration with the URL of a local source repository to which you want to update your artifacts.

26Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Viewing Maven Artifacts

27Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Dependency Repository

o Where we download all of our dependencies from • Can contain just releases and/or snapshots • Not uncommon to have them in separate repositories

o How do we specify our own repository

28Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

IDE Integration

29Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Importing Maven Projects

• Modern IDEs have Maven integration built into them • Maven integration will allow us to execute default maven goals within

our IDE • IDE configuration and Classpath will be set from Maven • Right Click in the Package Explorer > Import > Maven > Existing Maven

Projects

30Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Pom Viewer

• Default view when you open the pom file • Pom overview shows the high level elements of your project • Changes made here are directly changing the source

31Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Dependencies

• Shows which dependencies we have installed and allows us to manipulate dependencies too

• Dependency Management (advanced topic) is also displayed • The add screen has searching capability

32Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

33Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

• What is a Version Control System?• DVCS : Cons. And Pros.• Basic Commands• Conflicts• Branches• Git Clients and Tools

34Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

What is a Version Control System ?

• Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

• There are 3 types of Version Control Systems :• Local Version Control Systems• Centralized Version Control Systems (e.g CVS and Subversion)• Distributed Version Control Systems (e.g Mercurial and Git)

35Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

DVCS : Cons. And Pros

• Advantages :• Everyone has their own local sandbox :make changes and roll back, all on the local machine• Fast : Diffs, commits and reverts are all done locally.• Works offline : Everything but pushing and pulling can be done without an internet

connection• Can share changes with one or two other people at a time if they want to get some

feedback before showing the changes to everyone.• Switching using branching is simple and quick

• Disadvantages :• If your project contains many large, binary files that cannot be easily compressed, the

space needed to store all versions of these files can accumulate quickly.• If your project has a very long history (50,000 change sets or more), downloading the

entire history can take an impractical amount of time and disk space.

36Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Basic Commands

• git init : create a new local repository• git clone : check out a repository

Usage : git clone /path/to/repository , git clone username@host:path• git add : add one or more files to index

Usage : git add <filename> , git add *• git commit : commit changes to head (locally)

Usage : git commit –m “commit message” , git commit -a• git push : send changes to the master branch of your remote repository

Usage : git push origin master• git fetch : update remote tracking branches

Usage : git fetch• git merge : Join two or more development histories together

Usage : git merge <branch>

37Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Basic Commands Cont.

• git pull : fetch and merge changes on the remove server to your working directoryUsage : git pull

• git stash: Stash the changes in a dirty working directory awayUsage : git stash , git stash pop

• git reset : drop all local changes and commitsUsage : git reset --hard origin/master

38Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Conflicts

• conflicts will always occur in Git when these three conditions are met:• A user is attempting to merge two branches.• Each of these branches contain a different version of the same file.• Both versions of the file are created after both branch's most recent divergence

in history.

* Tell git that you resolved the conflict by using the add command

39Confidential and propriety Galil Software, Ltd. Confidential and propriety Galil Software, Ltd.

April 18, 2023

Branches

• A branch represents an independent line of development• a way to request a brand new working directory, staging area, and project history

Master(main development

branch)

Master(main development

branch)

Master(main development

branch)

Release Version 1 Bug fix Release

Version 1.1

Testing Branch

Master(main development

branch)

Testing Branch

Master(main development

branch)

Master(main development

branch)

Testing Branch

40Confidential and propriety Galil Software, Ltd.

Thank you

April 18, 2023