-
Notifications
You must be signed in to change notification settings - Fork 1
Practice 2a ‐ Simple Gradle CI CD
Ármin Zavada edited this page Sep 19, 2024
·
3 revisions
- Personal GitHub account
- JDK 21, IntelliJ, Git, Gradle
- Create a new public, personal GitHub repository
- Essential to be public to use GitHub Actions!
- Init the repository and clone to your machine.
- Pull starting project state using the following commands:
git remote add ase-labs https://github.com/ftsrg-edu/ase-labs.git git fetch ase-labs git switch practice-2a git push -u origin
- Examine src directory
- Execute
gradle init
in the root directory of the project- Continue overwrite
- Basic project
- Name: Shingler
- All else default
- Examine generated files
- Set
gradlew
executable:git update-index --chmod=+x ./gradlew
- Commit and push added files.
-
Setup Java compilation
- Add the Java plugin
plugins { java }
- Configure JDK version to
Java 21
java.toolchain { languageVersion.set(JavaLanguageVersion.of(21)) }
- Add missing dependencies required for compilation
repositories { mavenCentral() } val slf4jVersion = "1.7.36" val log4jVersion = "2.23.1" val picoCliVersion = "4.7.6" val junitVersion = "5.10.0" dependencies { // implementation -> build and runtime implementation("org.slf4j:slf4j-api:$slf4jVersion") // logging API: slf4j implementation("info.picocli:picocli:$picoCliVersion") // not used during build time runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion") // logging implementation: log4j // just for test source set testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion") }
- CHECK:
./gradlew assemble
task should execute without fail.
- Add the Java plugin
-
Setup runnable distribution creation
- Add Application plugin
plugins { application }
- Configure application plugin
application { mainClass = "hu.bme.mit.ase.shingler.similarity.SimilarityApp" }
- CHECK: Run
./gradlew assemble
task again,build/distributions
should contain a tar file with all necessary artifacts packaged.
- Add Application plugin
-
Setup testing, add Jacoco plugin
- Add Jacoco plugin and configure test tasks
plugins { jacoco } tasks { test { useJUnitPlatform() testLogging.showStandardStreams = true finalizedBy(jacocoTestReport) } jacocoTestReport { inputs.files(test.get().outputs) } }
- CHECK:
./gradlew build
task should execute without fail - assemble and check.
- Add Jacoco plugin and configure test tasks
-
Commit and push added files.
- Create new
.github/workflows
directory - Create new
build.yml
file in.github/workflows
directoryname: Continuous Integration on: push: branches: - '**' jobs: build: name: Build runs-on: ubuntu-latest permissions: contents: read steps: - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: 21 distribution: adopt - name: Checkout code uses: actions/checkout@v4 - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - name: Gradle build run: ./gradlew build - name: Upload Artifacts uses: actions/upload-artifact@v4 with: path: | build/distributions/* build/reports/*
- Commit and push added files.
- CHECK: GitHub should automatically run the whole build process.