Repository: iluwatar/java-design-patterns
Issue: Make a separate build line in for Sonar analysis
Labels: type: enhancement
epic: build issue

I have overlooked that there will be two simultaneous reports generated for Sonar issues which I have overlooked.

- [ ] Dismiss Matrix building of the project.
- [ ] We need to split into two build pipelines, one for running sonar analysis against the latest `zulu` build, and one with the latest JDK build.
- [ ] Let us use the cache feature for `maven` dependencies.

_Originally posted by @ohbus in https://github.com/iluwatar/java-design-patterns/pull/1868#pullrequestreview-785844000_

Issue comments:

Pull request review comments:
Perhaps this should be called just `build` since the other is called `build-and-analyze`?
Here too, maybe we can call it just `Build on JDK 11`
I suggest `Build and run Sonar analysis on JDK 11.0.3`
This comment is not related to any line, but it would be great to have some comments above the code to explain operations. I mean it's getting rather complex and is no longer self-explanatory what we are doing.
You are correct.

Let us add some comments to help understand what is going on.

And things are going to be more complex once we start implementing the automatic code styling by spotless.

Patch that resolved the issue:
diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml
index 94406095e02a..3b1bcafb0630 100644
--- a/.github/workflows/maven-ci.yml
+++ b/.github/workflows/maven-ci.yml
@@ -24,6 +24,9 @@
 # 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
 
+# We are using two jobs here for testing our code on the latest JDK 11 build as well as a more satble build version of 11.0.3
+# You can see the full discussion here https://github.com/iluwatar/java-design-patterns/pull/1868#issue-1029459688
+
 name: Java CI
 
 on:
@@ -33,12 +36,11 @@ on:
 
 jobs:
 
-  build:
+  # This Workflow Job will build this project and run Sonar analysis using JDK 11.0.3
+  build-and-analyze:
 
+    name: Build and Run Sonar analysis on JDK 11.0.3
     runs-on: ubuntu-20.04
-    strategy:
-      matrix:
-        java-version: [ 11.0.3, 11 ]
     steps:
 
     - name: Checkout Code
@@ -47,12 +49,14 @@ jobs:
         # Disabling shallow clone for improving relevancy of SonarQube reporting
         fetch-depth: 0
 
-    - name: Set up JDK ${{ matrix.java-version }}
+    - name: Set up JDK 11.0.3
       uses: actions/setup-java@v2
       with:
-        java-version: ${{ matrix.java-version }}
+        java-version: 11.0.3
         distribution: 'zulu'
+        cache: 'maven'
 
+    # Cache Sonar packages which as used to run anaylysis and collect metrics
     - name: Cache SonarCloud packages
       uses: actions/cache@v2
       with:
@@ -60,14 +64,6 @@ jobs:
         key: ${{ runner.os }}-sonar
         restore-keys: ${{ runner.os }}-sonar
 
-    - name: Cache Maven dependencies
-      uses: actions/cache@v2
-      with:
-        path: ~/.m2/repository
-        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
-        restore-keys: |
-          ${{ runner.os }}-maven-
-
     # Some tests need screen access
     - name: Install xvfb
       run: sudo apt-get install -y xvfb
@@ -78,3 +74,28 @@ jobs:
         # These two env variables are needed for sonar analysis
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
+
+  
+  # This Workflow Job is going to build the project on the latest stable JDK 11
+  build:
+
+    name: Build and Test on JDK 11
+    runs-on: ubuntu-20.04
+    steps:
+
+    - name: Checkout Code
+      uses: actions/checkout@v2
+
+    - name: Set up JDK 11 (Latest)
+      uses: actions/setup-java@v2
+      with:
+        java-version: 11
+        distribution: 'zulu'
+        cache: 'maven'
+
+    # Some tests need screen access
+    - name: Install xvfb
+      run: sudo apt-get install -y xvfb
+
+    - name: Build with Maven
+      run: xvfb-run ./mvnw clean verify
diff --git a/.github/workflows/maven-pr-builder.yml b/.github/workflows/maven-pr-builder.yml
index c1fd2bd82beb..8e5c5d9c7ced 100644
--- a/.github/workflows/maven-pr-builder.yml
+++ b/.github/workflows/maven-pr-builder.yml
@@ -34,11 +34,13 @@ on:
 jobs:
   build:
 
+    name: Build JDP
     runs-on: ubuntu-20.04
     strategy:
       matrix:
         java-version: [ 11.0.3, 11 ]
     steps:
+    
     - name: Checkout Code
       uses: actions/checkout@v2
     
@@ -47,14 +49,7 @@ jobs:
       with:
         java-version: ${{ matrix.java-version }}
         distribution: 'zulu'
-    
-    - name: Cache Maven Dependecies
-      uses: actions/cache@v2
-      with:
-        path: ~/.m2/repository
-        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
-        restore-keys: |
-          ${{ runner.os }}-maven-
+        cache: 'maven'
     
     # Some tests need screen access
     - name: Install xvfb


Test patch: