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 issue will be added by separate commits. Everything that will be necessary, I will describe here. If I miss something or describe it not clearly enough - ask in the comments, I will try to answer.
Writing 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 . How to do this through the idea I described here . So it will be more convenient and clearer for us in the future to track the work. Did you already know that there is no longer a master branch? Now it is called neutral - main . So we get used to it. Although, in truth, 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 proposed version of the boot sprint is 2.3.7, we take it. I will describe the following settings separately:- Project: Maven Project - we have already dismantled 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. There will be a desire - we can rewrite this case in Kotlin. I just bought myself a book Kotlin in Action, we will learn Kotlin together))
- Spring Boot: 2.3.7 - we take the smallest of the proposed versions to eliminate any problems. This is already a completely modern version of the boot.
- Group: com.github.codegymcommunity - here we select the domain hosting our group of repositories.
- Artifact: codegym-telegrambot - the maximum description of the project.
- Name: Javarush TelegramBot - we will 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.codegymcommunity.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 are in different packages. Each in its own unique. This is important to keep the OOP principles.
- Packaging: Jar is our standard)
- Java: 11 - let's be one step ahead. I do not 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 little easter egg in the future)
Setting up the CI process
We go into the created pull request: at the bottom we see that we do not have Continuous Integration configured (hereinafter - CI). Well, not configured, so what? Why do we need CI at all? What is CI anyway? Here is roughly the list of questions that should worry us at this moment. In general, CIis a continuous process of merging code into a common codebase with a project build running before. The so-called build (from the English build). Every time we build a project, we make sure that the project has been compiled, all of its tests have passed, plus after building the project, you can add autotests from testers that run on this particular build to CI. In this way, it turns out that we become more confident that new changes work as we expect and do not break the previous functionality. Also, CI is good in that it starts automatically after updating the codebase. 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 a broken build and cannot be merged into the main branch. This is what we will do now: Let's add GitHub Actions, which will run our code after the push. GitHub Actions fits perfectly with our GitHub Flow, so we will use it to automate the work. This tool is very powerful and big, but for now we will only use it to run the build and check that it builds as it should. To enable it, find the button on the repository pageActions and go through it: Find the Continuous Integration workflow we need: Click Set up this workflow. Further, we are offered to use their template: we fully agree, we will 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
Here it is indicated that the 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