Skip to content

Commit 0ca62a7

Browse files
Merge pull request sahil-sagwekar2652#90 from Abhinavcode13/patch-1
Create create_build.sh
2 parents e2ca986 + 48bf44f commit 0ca62a7

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
---
3+
4+
# Maven Build Script
5+
6+
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.
7+
8+
## Prerequisites
9+
10+
Before running this script, ensure that you have the following prerequisites installed:
11+
12+
- [Maven](https://maven.apache.org/) - The Apache Maven build tool.
13+
- [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.
14+
15+
## Usage
16+
17+
To use this script, follow the steps below:
18+
19+
1. Open a terminal or command prompt.
20+
2. Navigate to the directory where the script is located.
21+
3. Make the script executable, if necessary, using the command: `chmod +x build.sh`
22+
4. Run the script using the command: `./build.sh`
23+
24+
## Script Explanation
25+
26+
The script performs the following steps:
27+
28+
1. **Clean the Project**: The command `mvn clean` is executed to clean the project directory by removing any previously compiled files or artifacts.
29+
30+
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).
31+
32+
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`.
33+
34+
4. **Run Tests**: The command `mvn test` is executed to run any defined tests for the project.
35+
36+
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`.
37+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Clean the project
4+
mvn clean
5+
6+
# Build the project
7+
mvn package
8+
9+
# Check if the build was successful
10+
if [ $? -eq 0 ]; then
11+
echo "Build completed successfully."
12+
else
13+
echo "Build failed."
14+
exit 1
15+
fi
16+
17+
# Run tests
18+
mvn test
19+
20+
# Check if tests passed
21+
if [ $? -eq 0 ]; then
22+
echo "All tests passed."
23+
else
24+
echo "Some tests failed."
25+
exit 1
26+
fi
27+
28+
# Additional steps can be added here, such as generating documentation or creating artifacts
29+
30+
# If everything succeeded, the built artifacts can be found in the target/
31+
32+
#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.
33+
34+
#To execute the script, navigate to the directory containing the script file (build.sh) in the terminal and run ./build.sh.
35+
36+
#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 commit comments

Comments
 (0)