Q1. What are the general steps involved in making a software release?
A1.
#1: Checking out the software artifacts to you build serevr or local box from a source control management (i.e. SCM) system.
#2: Giving it a version so it can be uniquely identifieds
#3: Building, testing and packaging the artifacts.
#4: Deploying the built artifacts a repository like Nexus where the artifacts can be picked up for for actual roll out on target servers by the release team.
#5: Tagging this state in SCM so it can be associated with the matching artifacts.
Q2. How will you go about using Git and Maven to perform software releases?
A2.
Step #1: Checking the software out from Git and checkout if you want to release from a branch
1 | git clone ssh://user@server:/GitRepos/myproject.git |
1 | git checkout my-current-branch |
Step #2: Giving it a version. “0.0.1-SNAPSHOT” in pom.xml becomes “0.0.2-RC1” (that is Release Candidate 1)
1 | mvn versions:set -DnewVersion=0.0.2-RC1 |
You should not have any “SNAPSHOT” in your multi-module pom files.
1 | find . -maxdepth 2 -type f -name pom.xml -exec grep SNAPSHOT {} \; |
If you find any “SNAPSHOT”, manually update them with something like
1 | find . -maxdepth 2 -type f -name pom.xml -exec grep 1.0.1-SNAPSHOT {} \; -exec sed -e "s/1.0.1-SNAPSHOT/1.0.2/g" {} \; |
Step #3: Building, testing, packaging and deploying it to an artifact repository like Nexus.
1 | mvn deploy |
You need to have the path to the Nexus configured in your pom.xml with “distributionManagement”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <distributionManagement> <snapshotRepository> <id>myapp-snapshots</id> <name>MyApp Snapshots</name> <url>http://sdlc/nexus/content/repositories/myapp-snapshots</url> <uniqueVersion>false</uniqueVersion> </snapshotRepository> <repository> <id>myapp-releases</id> <name>MyApp Releases</name> <url>http://sdlc/nexus/content/repositories/myapp-releases</url> </repository> </distributionManagement> |
and the Maven settings.xml configured with user/password to connect to the Nexus repo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <settings> ... <servers> <server> <id>bfs-releases</id> <username>user</username> <password>password</password> </server> <server> <id>bfs-snapshots</id> <username>user</username> <password>password</password> </server> </servers> .... <proxies> <proxy> <id>myproxy</id> <active>true</active> <protocol>http</protocol> <host>proxy.mya pp</host> <port>8080</port> <username>user</username> <password>password</password> </proxy> </proxies> </settings> |
Step #4: Tagging this state in SCM.
1 | mvn scm:tag -Dtag="0.0.2-RC1" |
You need to have the “SCM” configured in your pom.xml file
1 2 3 4 5 6 | <scm> <url>ssh://git@stash.internal.myhost.com/myproject/my-app.git</url> <connection>scm:git:ssh://git@stash.internal.myhost.com/myproject/my-app.git</connection> <developerConnection>scm:git:ssh://git@stash.internal.myhost.com/myproject/my-app.git</developerConnection> </scm> |
Step #5 Advance with the maven pom.xml tags to 0.0.3-SNAPSHOT to continue with the development work.
1 | mvn versions:set -DnewVersion=0.0.3-SNAPSHOT |
Note: in your pom.xml file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>versions-maven-plugin</artifactId> <version>1.3.1</version> <configuration> <generateBackupPoms>false</generateBackupPoms> </configuration> </plugin> </plugins> </pluginManagement> </build> |
if you have set the “generateBackupPoms” to “true” then you need to run “mvn versions:commit” or “mvn versions:rollback”.
The “scm” plugin needs the following config in the pom.xml file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ... <scm> <url>ssh://git@stash.internal.mydomain.com/myplatforms/myapp.git</url> <connection>scm:git:ssh://git@stash.internal.mydomain.com/myplatforms/myapp.git</connection> <developerConnection>scm:git:ssh://git@stash.internal.mydomain.com/myplatforms/myapp.git</developerConnection </scm> .... <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-scm-plugin</artifactId> <version>1.4</version> <configuration> <connectionType>developerConnection</connectionType> </configuration> </plugin> </plugins> </pluginManagement> </build> |
The “versions” and “scm” plugins give you better control in releasing your software artifacts. There is another approach where Maven does most of the hard work for you if your release is very straight forward. This is with the help of the maven “release” plugin. In the pom.xml file you need to have
1 2 3 4 5 6 7 8 9 | <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.2.1</version> <configuration> <autoVersionSubmodules>true</autoVersionSubmodules> </configuration> </plugin> |
and then use it in the command-line as:
1 2 3 | mvn release:prepare mvn release:perform |
You may also like: Git source control Q&A | 12 Maven interview Questions & Answers | 7 More Maven interview Questions & Answers