Earning Build badge

This article gives you pointers on how to earn the build badge.

Build overview

Build scripts help you work easily in a continuous integration environment. 

The usual suspects - common pitfalls while earning Build badge

1. No build script :)

If you're new to build scripts, see section below with the Java example. And we have provided a link to language specific artefacts at the end of this article.

2. The build script does not fulfil these 4 criteria 

When you write build scripts, write it in a manner that it can execute on any machine. The build script should: 

  • should build out your solution on any operating system 
  • execute your solution 
  • run tests 
  • and handle dependencies

Java code solution example using Maven as a build tool:

If you are new to build systems and have not used Maven before, please read these articles to understand how to set up a Java project with:

These articles are guidelines to get you started. For Geektrust backend coding problems you have to use the pom.xml file we provide. You will have to use one of them in your Java project depending on what build file you select. Please download the files from here.

Maven pom.xml

In the Maven pom.xml file we have provided a maven-assembly-plugin which is used to create a single jar file, aggregated with its dependencies, modules, site documentation, and other files. Please do not edit the finalName (geektrust in this case) under its configuration section. Make sure the 'finalName' tag is inside the maven-assembly-plugin configuration. This should generate an executable 'geektrust.jar' in the target folder.

Add the fully qualified name of your Main class file in the mainClass section under manifest. You can also edit the Group ID and the Artifact ID.

We build and run the solution by using the following command

java -jar geektrust.jar <path_to_input_file><br>

E.g., if the fully qualified name of your Main class in the project is com.example.Main then your pom.xml will look like this

<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.example</groupId>
	<artifactId>geektrust-problems</artifactId>
	<version>1.0</version>
	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
	</properties>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
					<finalName>geektrust</finalName> <!-- Please do not change this final artifact name-->					
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
					<appendAssemblyId>false</appendAssemblyId>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<!-- This is the main class of your program which will be executed-->
							<mainClass>com.example.Main</mainClass>
						</manifest>
					</archive>
				</configuration>

				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

		</plugins>
	</build>
</project>

Compilation and Execution

For Maven, run the following commands to compile & execute

mvn clean install -DskipTests -q assembly:single
java -jar <path_to>/geektrust.jar <absolute_path_to_input_file>

You could find language specific build artefacts here.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us