0% found this document useful (0 votes)
0 views

Devops Lab Program 1 18

The document provides a comprehensive guide on using Maven and Gradle for build automation, including installation steps and project setup in Eclipse. It covers creating Maven projects, understanding the POM file, and migrating projects from Maven to Gradle. Additionally, it introduces Jenkins and its installation process for local or cloud environments.

Uploaded by

sudha.s
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Devops Lab Program 1 18

The document provides a comprehensive guide on using Maven and Gradle for build automation, including installation steps and project setup in Eclipse. It covers creating Maven projects, understanding the POM file, and migrating projects from Maven to Gradle. Additionally, it introduces Jenkins and its installation process for local or cloud environments.

Uploaded by

sudha.s
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

PROGRAM-1

Introduction to Maven and Gradle: Overview of Build Automation Tools, Key


Differences Between Maven and Gradle, Installation and Setup

VTU LAB
STEP1:Install Eclipse using this link
https://www.eclipse.org/downloads/
ENTERPRISE JAVA AND WEB DEVELOPERS

PROGRAMS

STEP2:Select ECLIPSE IDE FOR JAVA DEVELOPER OR ECLIPSE IDE FOR


STEP3:SELECT INSTALLATION FOLDER JAVA VERSION
STEP4:ONCE ECLIPSE IS INSTALLED THE SCREEN LOOKS AS IN BELOW

PROGRAMS

STEP5:Lets see Procedure to install MAVEN & GRADLE


a) First make sure JDK current version is installed
https://www.oracle.com/java/technologies/downloads/?er=221886#jdk23-wi
ndows

LA
Then set environment variable path both user and system
■ Have a JDK installation on your system. Either set the JAVA_HOME
environment variable pointing to your JDK installation or have the

B
java executable on your PATH.

VTb) To install apache maven pls go to link as in below and download zip file
of bin
https://maven.apache.org/download.cgi

U
c) To unzip the Source zip archive
Run in Windows cmd prompt
unzip apache-maven-3.9.9-bin.zip
If don't want to run directly extract the file to Program Files

PROGRAMS
d) Setup a PATH in environmental settings

“Add the bin directory of the created directory apache-maven-3.9.9 to the

PATH environment variable”

e) After environment variable is set

Run this command in CMD

prompt mvn --v(2 hyphen)

After running, you see the text screen as in below

LA
B
VT
f) TO INSTALL GRADLE FOR WINDOWS follow procedure as in below
1. Create a new directory C:\Gradle with File Explorer.
2. Open a second File Explorer window and go to the directory where the

U
Gradle distribution was downloaded. Double-click the ZIP archive to
expose the content. Drag the content folder gradle-8.12.1 to your newly
created C:\Gradle folder.

Alternatively you can unpack the Gradle distribution ZIP into C:\
Gradle using an archiver tool of your choice or run command with
path folder where the folder is created.
unzip apache-maven-3.9.9-bin.zip
Or can directly extract the zip file.
3. Configure your system environment
4. Finally type the command gradle –v to check if the gradle is installed.

VTU LAB
PROGRAMS

PROGRAM-2
Working with Maven: Creating a Maven Project, Understanding the POM
File, Dependency Management and Plugins

STEP1:OPEN ECLIPSE THEN follow this navigation


FIle —-----> New--------->Maven Project
After that Screen be as in below
VTU LAB
PROGRAMS
STEP2:Make sure Use default Workspace Location is selected, then click
Next

The screen be as in below

STEP3:In Screen shown above, click near the entry place of Filter and type
“apache” or select catalog as Internal
We want a simple maven JAR based application. So, we will choose
the “maven-archetype-quickstart” artifact to create the project.
VTU LAB
PROGRAMS
STEP4: Enter
Group Id:com.program2.maven
Artifact Id:program2-example-jar
Keep snapshot as it is
Package:com.program2.maven.program2

VTU LAB
PROGRAMS

After entering above mentioned details click on Finish


You be able to see the automation build happening for Maven Jar Project
It asks for Configuration confirmation just click Y

Confirm properties configuration:


groupId: com.program2.maven
artifactId: program2-example-jar
version: 0.0.1-SNAPSHOT

VTU LAB
package: com.program2.maven.program2

The RESULT be as in below

PROGRAMS

STEP5:Now its time to build Maven Project


Go to Maven Project--------------->Right Click on the Project and select
Maven Build
After the above procedure is done
Select Goal as package

VTU LAB
PROGRAMS

And Click Run


The result be as in below
Now goto App.java finally run java application

PROGRAMS

Description
What is groupId in maven ?
groupId identifies a particular project uniquely across all projects, so we should follow a

LA
naming convention. A very simple and commonly used way of doing this is to use the
reverse of your domain, i.e. com.javarewind.maven.

A good way of maintaining the integrity of groupId is to use the project structure. In
case the project consists of multiple modules then every module should append an

B
identifier to the parent groupId.
i.e. com.javarewind.maven, com.java rewind.spring, com.javarewind.struts .. etc.

What is artifactId in maven ?

VT
artifactId is the name of war file without version, if you are creating it by yourself you
are free to took any name of your choice in lower case and without any strange
symbol. But if this is a third party jar than we have to take the name of the jar as

U
suggested by its distribution.

What is the archetype in maven ?


Archetype is a Maven project templating toolkit which tells the maven the type of
project we are going to create. Archetype enables the maven to create a template
project of the user's choice so that the user can get the project up and running
instantly.

“archetype:generate” generates a new project from the provided archetype or


updates the actual project if using a partial archetype. Maven provides a number of
predefined archtypes, see more details from Maven Documentation.


HOW POM.XML LOOKS IS AS IN SCREEN BELOW

VTU LAB
PROGRAMS
PROGRAM3:Working with Gradle: Setting Up a Gradle Project,
Understanding Build Scripts (Groovy and Kotlin DSL), Dependency
Management and Task Automation

STEP1:Let's do this in cmd prompt


Goto Command Prompt

VTU LAB
Then first make a new directory the command is
mkdir pgm3

PROGRAMS
For changing to a current directory the command is
cd pgm3

Now run
gradle init
After execution of command the screen shows as in below where we opt
for build type select as 1

After selecting application type next it asks for Implementation language


select as groovy

After selecting Implementation language it will ask for Java version and
project name
VTU LAB
After providing version and project name
Select application structure as Single application structure and Domain
Specific Language as Kotlin

PROGRAMS

After every procedure is over it shows Build successful

STEP2:Now its time to Build the script


Just type the command as:
gradlew run

It will take atleast 3-5 minutes to run the configuration script we have set
through steps finally the output be as in below If You want to see the
structure of an application run the command as tree
VTU LAB
PROGRAMS

PROGRAM4:Practical Exercise: Build and Run a Java Application with


Maven, Migrate the Same Application to Gradle

STEP1: First create a Maven Project as in PROGRAM2 then build the


project and run java application you will get Hello World Message

STEP2:Then to migrate to gradle use shortcut Key Ctrl+Alt+Shif+T To get


Terminal screen as in below:
VTU LAB
PROGRAMS

STEP3: Type command gradle init it will ask for migrate from maven to
gradle type yes

STEP4: After the above command is validated to yes it prompts to


select Domain Specific Language as in screen below select 2 (as we
have done for Kotlin)
VTU LAB
STEP5:After selecting Groovy it asks for validating prompt for
API Generator just validate as yes

PROGRAMS

Finally it runs the init phase as been selected

STEP6:
Type the
command gradle
build
Now to get exact program output of our java file Locate to build gradle File from ur
local repository and Copy paste the code as in below shown in red color

plugins {
id("java-library")

VTU LAB
id("maven-publish")
id("application")
}

PROGRAMS
application {
mainClass.set("com.pgm4.test.App") // Use .set() for properties
}

repositories {
mavenCentral()
// Uncomment if you need to publish locally
// mavenLocal()
}

dependencies {
testImplementation("junit:junit:4.13.2") // Use Kotlin syntax for dependencies
}

group = "com.pgm4.test"
version = "0.0.1-SNAPSHOT"
description = "pgm4"
java.sourceCompatibility = JavaVersion.VERSION_11 // Consider upgrading

publishing
{ publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}

tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
tasks.withType<Javadoc>().configureEach {
options.encoding = "UTF-8"
}

VTU LAB
AFTER DOING ALL CHANGES FINAL STEP
To run
commands gradle
clean build gradle

PROGRAMS
run
You will get Output as
Hello World! Welcome to pgm4

PROGRAM5:Introduction to Jenkins: What is Jenkins?, Installing Jenkins on Local or Cloud


Environment, Configuring Jenkins for First Use .

STEP1: Type jenkins download for windows


https://www.jenkins.io/download/

You might also like