An article from a series about creating a Java project (links to other materials are at the end). Its goal is to analyze key technologies, the result is to write a telegram bot. Greetings, dear readers. As described in the previous part, we will go according to plan. We have already created a project and it’s time to fill it with code. Now all issues will be added as separate commits. I will describe everything that is necessary here. If I miss something or don’t describe it clearly enough, ask in the comments, I’ll try to answer.
We write JRTB-0M
In this task we need to add an empty SpringBoot framework for future work. We will do this in the same way as we did in the article about SpringBoot + Flyway . Download the project , open it in IDEA and create a new branch called JRTB-0 . I described how to do this through an idea here . This will make it easier for us to track work in the future. Did you already know that there is no longer a master branch? Now it is called neutrally - main . So we get used to it. Although, to be honest, we can always rename it back to master. We go to Spring Initializr and create a SpringBoot framework for our bot. At the moment, the youngest version of the boot sprint offered is 2.3.7, let's take it. I will describe the following settings separately:- Project: Maven Project - we have already discussed Maven here and here . Therefore, I will additionally describe only what I did not disclose in previous articles. If there are such “white spots”, of course)
- Language: Java - everything is clear here. If there is a desire, we can rewrite this matter in Kotlin. I just bought myself a book Kotlin in Action, we’ll learn Kotlin together))
- Spring Boot: 2.3.7 - we take the smallest version offered to eliminate any problems. This is already a completely modern version of the boot.
- Group: com.github.javarushcommunity - here we select the domain on which our group of repositories is hosted.
- Artifact: javarush-telegrambot - maximum description of the project.
- Name: Javarush TelegramBot - we’ll write it in full here.
- Description: Telegram bot for Javarush from community to community - here is a more detailed description of the project.
- Package name: com.github.javarushcommunity.jrtb - here you can already use an abbreviation for the project name. Now the project will start with this package. Why so many? So that when we add other projects to the classpath, they will be in different packages. Each in their own unique way. This is important to maintain OOP principles.
- Packaging: Jar is our standard)
- Java: 11 - we'll be one step ahead. I don’t think that I will use innovations after the eighth Java, but let it be. He doesn’t ask for food)... this decision will give us a small Easter egg in the future)
Setting up the CI process
We go to the created pull request: below we see that we do not have Continuous Integration configured (hereinafter - CI). Well, it’s not configured, so what? Why do we need CI at all? What is CI anyway? This is approximately the list of questions that should concern us at this moment. In general, CI is a continuous process of merging code into a common code base and running a build of the project before that. The so-called build (from English build). Every time we build a project, we make sure that the project has been compiled, all its tests have passed successfully, plus after building the project, you can add autotests from testers to CI that are run on this specific build. This way, we become more confident that the new changes work as we expect and do not break the previous functionality. CI is also good because it starts automatically after updating the code base. That is, we pushed our changes into the branch and the process began - assembly, tests, autotests and other steps. If any of these steps fail, the build is considered broken and cannot be merged into the main branch. This is exactly what we will do now: we will add GitHub Actions, which will run our code after the push. GitHub Actions fits perfectly into our GitHub Flow, so we will use it to automate our work. This tool is very powerful and large, but for now we will only use it to run the build and check that it is assembled as needed. To enable it, find the Actions button on the repository page and follow it: Find the Continuous Integration workflow we need: Click Set up this workflow. Next, we are offered to use their template: we completely agree, let’s just clarify everything a little:# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
This indicates that GitHub Action is called in two cases:
- When a push is made to the main branch.
- When a pull request is created in the main branch.
GO TO FULL VERSION