As part of my CodeAlpha DevOps Internship, I worked on a project that helped me understand how Java applications can be built, tested, and packaged using Gradle.
Before this project, I had been working more with Docker, Terraform, and cloud deployment. This project gave me the opportunity to focus on the application build process and how CI/CD automation can help make it more reliable.
The goal was simple: build a Java application, test it, generate a JAR file, and automate the process using GitHub Actions.
What I wanted to achieve
For this project, I wanted to:
- Create a simple Java application.
- Use Gradle to manage the build process and dependencies.
- Write unit tests using JUnit 5.
- Generate an executable JAR file.
- Automate the build and testing process with GitHub Actions.
- Make the generated JAR available as a workflow artifact.
Tools and technologies
The project used the following tools:
| Tool | Purpose |
|---|---|
| Java 21 | Application development |
| Gradle 8.14.3 | Build automation and dependency management |
| JUnit 5 | Unit testing |
| GitHub Actions | CI automation |
| Git and GitHub | Version control and code hosting |
Creating the Java application
I created a Java project named cloudops-java-app.
The application is a simple CloudOps build monitor. It displays information such as the application name, version, build status, Java version, and a greeting.
Although the application itself is small, it gave me a practical way to work through the Java build lifecycle.
The application entry point is:
com.codealpha.cloudops.App
I also configured the project to generate an executable JAR with the correct Main-Class in its manifest. This allows the application to be run directly using the Java command.
Setting up Gradle
I used the Gradle Wrapper rather than depending on a globally installed Gradle version.
The wrapper helps ensure that the project uses the Gradle version defined for it. This is useful when another developer or a CI runner needs to build the project.
I configured the project to use Java 21 and added the dependencies required for the application and its tests.
Gradle handled the build tasks, dependency resolution, compilation, testing, and packaging.
Writing and running unit tests
I added unit tests using JUnit 5.
The tests helped me verify that the application behaved as expected before creating the final package.
I ran the tests locally using:
./gradlew test
The test task completed successfully, with 5 tests passed and 0 failures.
I then ran the complete build:
./gradlew clean build
This cleaned the previous build output and ran the build tasks again.
The build completed successfully.
Generating and running the JAR
After the build, Gradle generated the executable JAR file at:
app/build/libs/app.jar
I checked the contents of the JAR to confirm that the application classes and manifest were included.
I also ran the application directly:
java -jar app/build/libs/app.jar
This confirmed that the packaged application could start without needing to run it through Gradle.
Automating the build with GitHub Actions
Once the local build was working, I moved on to CI automation.
I created a GitHub Actions workflow at:
.github/workflows/gradle-ci.yml
The workflow runs when I push changes or create a pull request affecting the Project 3 files. It can also be started manually.
The workflow performs the following steps:
- Checks out the repository.
- Sets up Java 21.
- Prepares the Gradle build environment.
- Runs the Gradle build and tests.
- Uploads the generated JAR file as a workflow artifact.
The build command used in the workflow is:
./gradlew build
I encountered a small issue during the initial workflow run. GitHub Actions reported that the Gradle Wrapper could not be executed because it did not have executable permission.
I fixed the file permission in Git and pushed the change.
After that, the workflow ran successfully.
Successful CI pipeline
The final GitHub Actions run completed successfully.
The pipeline built the Java application, ran the tests, and uploaded the JAR file as an artifact.
This was an important part of the project because it showed that the application could be built and tested in a clean CI environment, not only on my local machine.
The uploaded artifact can be downloaded from the successful workflow run in GitHub Actions.
Build workflow
The process I implemented can be summarized as:
- I make changes to the Java application.
- I push the changes to GitHub.
- GitHub Actions starts the workflow.
- Gradle builds the application and runs the tests.
- If the build succeeds, the JAR file is uploaded.
- The artifact can then be downloaded and run.
If the build or tests fail, the workflow reports the failure so I can review the logs, fix the issue, and push the changes again.
What I learned
This project helped me understand the role of build automation in a software delivery process.
I learned how Gradle manages a Java project's build tasks and dependencies, how JUnit can be used to test application behavior, and how an executable JAR is generated.
I also gained practical experience configuring GitHub Actions and troubleshooting a CI issue related to file permissions.
One important lesson was that a successful local build is not enough. Automating the build in GitHub Actions helps confirm that the project can be built consistently in another environment.
Conclusion
This project was a useful step in my DevOps learning journey.
I was able to take a Java application from source code through testing and packaging, then automate the process using GitHub Actions.
The project does not deploy the application to a live server. Instead, it focuses on the build and test stage of a CI/CD workflow, with the JAR file delivered as a downloadable artifact.
I look forward to applying these build automation and CI practices to larger applications and more complete deployment pipelines.
Project repository: CodeAlpha DevOps Internship Projects
Project 3: Java Application Using Gradle

Top comments (0)