Skip to content

Commit

Permalink
Merge pull request #90 from Abhinavcode13/patch-1
Browse files Browse the repository at this point in the history
Create create_build.sh
  • Loading branch information
sahil-sagwekar2652 authored Jul 26, 2023
2 parents e2ca986 + 48bf44f commit 0ca62a7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scripts/Maven build script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

---

# Maven Build Script

This script is designed to build and test a Maven project. It automates the process of cleaning the project, building the project, and running tests. It also provides feedback on the success or failure of each step.

## Prerequisites

Before running this script, ensure that you have the following prerequisites installed:

- [Maven](https://maven.apache.org/) - The Apache Maven build tool.
- [Java Development Kit (JDK)](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html) - The Java development kit required for building and running the project.

## Usage

To use this script, follow the steps below:

1. Open a terminal or command prompt.
2. Navigate to the directory where the script is located.
3. Make the script executable, if necessary, using the command: `chmod +x build.sh`
4. Run the script using the command: `./build.sh`

## Script Explanation

The script performs the following steps:

1. **Clean the Project**: The command `mvn clean` is executed to clean the project directory by removing any previously compiled files or artifacts.

2. **Build the Project**: The command `mvn package` is executed to build the project. This step compiles the source code, runs any necessary tests, and packages the application into an executable artifact (e.g., JAR file).

3. **Check Build Status**: The script checks the exit code of the previous command using `$?`. If the exit code is `0`, it indicates a successful build. The script displays the message "Build completed successfully." Otherwise, it displays the message "Build failed." and exits with status `1`.

4. **Run Tests**: The command `mvn test` is executed to run any defined tests for the project.

5. **Check Test Results**: Similar to the previous step, the script checks the exit code of the previous command. If the exit code is `0`, it indicates that all tests passed. The script displays the message "All tests passed." Otherwise, it displays the message "Some tests failed." and exits with status `1`.

36 changes: 36 additions & 0 deletions scripts/Maven build script/maven_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Clean the project
mvn clean

# Build the project
mvn package

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "Build completed successfully."
else
echo "Build failed."
exit 1
fi

# Run tests
mvn test

# Check if tests passed
if [ $? -eq 0 ]; then
echo "All tests passed."
else
echo "Some tests failed."
exit 1
fi

# Additional steps can be added here, such as generating documentation or creating artifacts

# If everything succeeded, the built artifacts can be found in the target/

#Save this script in a file named build.sh, and make sure to provide the necessary permissions to execute the script by running chmod +x build.sh in the terminal.

#To execute the script, navigate to the directory containing the script file (build.sh) in the terminal and run ./build.sh.

#Make sure you have Maven installed and configured correctly in your environment before running this script. Adjust the script or include additional steps as needed based on your project's requirements.

0 comments on commit 0ca62a7

Please sign in to comment.